Duration.Hours

D

T

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

What is the Duration.Hours function?

The Duration.Hours function is a Power Query function that returns the number of hours in a duration value. The function is used to extract the number of hours from a time duration value, which could be useful in a variety of scenarios. For example, you might use the function to calculate the number of hours worked by an employee, or the duration of a movie.

The M code behind Duration.Hours

The M code behind the Duration.Hours function is relatively simple. The function takes a single argument, which is a duration value, and returns the number of hours in the duration. Here is the M code for the function:


(Duration) =>

Duration.TotalHours


The code above defines an anonymous function that takes a single argument, which is a duration value. The function then returns the number of hours in the duration value using the TotalHours property of the duration.

Using Duration.Hours in Power Query

Now that we understand the M code behind the Duration.Hours function, let's take a look at how it can be used in Power Query. Suppose we have a table with a column of duration values, and we want to create a new column that contains the number of hours in each duration value. We can do this using the following steps:

1. Select the duration column in the table.

2. Click the "Add Column" tab and select "Custom Column".

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


Duration.Hours([DurationColumn])


Replace "DurationColumn" with the name of the duration column in your table.

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

The new column will contain the number of hours in each duration value.

In this article, we have explored the M code behind the Power Query function Duration.Hours. We have seen that the function is relatively simple, taking a single argument and returning the number of hours in a duration value. We have also seen how the function can be used in Power Query to create new columns that contain the number of hours in duration values. With this knowledge, you can now use the Duration.Hours function to manipulate duration data in your Power Query projects.

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)