# Duration.TotalMinutes

## What is Duration.TotalMinutes?

Before we dive into the M code behind Duration.TotalMinutes, let’s first understand what this function does. As mentioned earlier, this function converts a duration value to minutes. In other words, it takes a time-based value in the format of hours, minutes, and seconds and converts it to minutes. For example, if you have a duration value of 01:30:00 (1 hour, 30 minutes, and 0 seconds), the Duration.TotalMinutes function would return the value 90 (90 minutes).

## The M Code Behind Duration.TotalMinutes

The M code behind the Duration.TotalMinutes function is relatively simple. The function takes a single argument, which is the duration value to be converted to minutes. This argument can be either a duration value or a column reference that contains duration values.

Here is the M code for the Duration.TotalMinutes function:

(duration as duration) =>

Duration.TotalMinutes(duration)

``` As you can see, the function takes the duration value as an argument and passes it to the internal Power Query function Duration.TotalMinutes. This function then converts the duration value to minutes and returns the result. Using Duration.TotalMinutes in Power Query Now that we understand the M code behind the Duration.TotalMinutes function, let's take a look at how we can use it in Power Query. Suppose we have a table that contains a column of duration values, and we want to convert these values to minutes. To do this, we can use the Duration.TotalMinutes function in a new column. Here is the M code for this scenario: ```

let

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(“i45WcjQzNzS2MTGwMlGyUipWsgZi0YrJzUwMlGyUlISBmJQYnJxYkK5VqTnFQAKG1RyBi1GKyc1MDJRLzEwNzAtMy1UJzEwVcoqVooA1owNjA1MDS0MjU0MNMw0zQzNDSwMjYzSjY2N0jQ3MNIzUzIyNzESA”, BinaryEncoding.Base64)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),

#”Changed Type” = Table.TransformColumnTypes(Source,{{“Column1”, type duration}}),

``` In this code, we first create a new table from the source data that contains a column of duration values. We then use the Table.TransformColumnTypes function to convert this column to the duration data type. Finally, we add a new custom column that uses the Duration.TotalMinutes function to convert the duration values to minutes. In conclusion, the Duration.TotalMinutes function in Power Query is a powerful tool for working with time-based data. By converting duration values to minutes, this function makes it easier to perform calculations and analysis on time-based data. The M code behind this function is relatively simple, and understanding how it works can make it easier to use in your Power Query projects. Power Query and M Training Courses by G Com Solutions (0800 998 9248) Power Query and M Intensive Training Course £1,050.00 – £26,550.00 Select optionsContinue Loading Done Power Query and M Introduction £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Intermediate £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Advanced £395.00 – £9,750.00 Select optionsContinue Loading Done Upcoming Courses Contact Us Subject Your Name (required) Company/Organisation Email (required) Telephone Training Course(s) Power BI Intensive TrainingPower BI introduction Power BI IntermediatePower BI AdvancedDAXPower Query MPower BI CertificationPower BI AdministrationPower PlatformPower AutomatePower AppsOTHER Your Message Upload Example Document(s) (Zip multiple files) ```
``` ```
``` ```
``` ```
``` ```
``` ```