Duration.Minutes

D

T

The M Code Behind the Power Query M function Duration.Minutes

Understanding Duration.Minutes

Duration.Minutes is a function in Power Query that calculates the number of minutes in a duration value. A duration value is a time span that represents the difference between two dates or times. For example, if you have two dates: 1/1/2021 and 1/2/2021, the duration value would be 1 day. The Duration.Minutes function can then be used to calculate the number of minutes in that duration value.

The M Code Behind Duration.Minutes

To understand the M code behind Duration.Minutes, let’s first take a look at the syntax of the function:


Duration.Minutes(duration as duration) as number


The function takes one argument, which is the duration value that you want to calculate the number of minutes for. The argument is of type "duration" and the function returns a number.

Now, let's break down the M code for the function:


(duration as duration) as number =>

Duration.TotalMinutes(duration)


The first line defines the argument for the function, which is the duration value we want to calculate the number of minutes for. The second line uses the Duration.TotalMinutes function to calculate the total number of minutes in the duration value. The result is then returned as a number.

Using Duration.Minutes

Now that we understand the M code behind Duration.Minutes, 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 calculate the total number of minutes for each row. We can do this by adding a new column to the table and using the Duration.Minutes function:

1. Select the table.

2. Go to the "Add Column" tab and click "Custom Column".

3. In the "Custom Column" dialog, enter a name for the new column and the following formula:


Duration.Minutes([Duration])


4. Click "OK" to add the new column.

The above formula assumes that the column containing the duration values is named "Duration". You can replace this with the name of the actual column in your table. Once the new column is added, it will display the total number of minutes for each duration value.

In this article, we've explored the M code behind the Power Query M function Duration.Minutes. We've seen how the function can be used to calculate the number of minutes in a duration value and how it can be applied to real-world scenarios in Power Query. By understanding the M code behind this function and other Power Query functions, you can take your data analysis skills to the next level and improve your efficiency when working with large data sets in Excel.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)