Duration.TotalHours is a Power Query M function that calculates the total hours spanned by a duration value. The function returns a decimal number representing the total hours.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Duration.TotalHours( duration as nullable duration ) as nullable number
Description
The Duration.TotalHours function calculates the total number of hours (including fractions) in a duration.
Examples
Let’s see how we can use the Duration.TotalHours
function.
Calculating Total Hours from a Duration Value
The Duration.TotalHours
function calculates the total number of hours from a duration value. For example, a duration of 1 hour and 30 minutes returns 1.5 hours:
Duration.TotalHours( #duration( 0, 1, 30, 0 ) ) // Output: 1.5
This is different from the Duration.Hours function, as that function only retrieves the hours portion of a duration value after subtracting the days, minutes portion:
Duration.Hours( #duration( 0, 1, 30, 0 ) ) // Output: 1
The output of Duration.TotalHours
is also correct when the duration value specifies a combination of days, hours, minutes, and seconds. For instance, a duration of 1 day, 1 hour, and 30 minutes returns 25.5 hours:
Duration.TotalHours( #duration( 1, 1, 30, 0 ) ) // Output: 25.5
The output is the same when the duration value specifies 1530 minutes directly:
Duration.TotalHours( #duration( 0, 0, 1530, 0 ) ) // Output: 25.5
By using Duration.TotalHours
, you can easily compute the total number of hours within a duration, regardless of how the duration is composed.
Related functions
Other functions related to Duration.TotalHours are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy