Duration.TotalHours

Duration

Returns the total duration expressed as a fractional number of hours.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Duration.TotalHours(duration as nullable duration) as nullable number

Parameters

NameTypeRequiredDescription
durationdurationYesA duration value.

Return Value

numberThe total number of hours (including fractional parts) represented by the duration.

Remarks

Duration.TotalHours returns the entire duration as a decimal number of hours. For example, 1 day and 6 hours returns 30.0. This differs from Duration.Hours, which returns only the hours component of the duration (e.g., 6 for the same input, not 30). Use Duration.TotalHours when you need elapsed time as a single numeric value — for example, for SLA calculations, hourly billing, or rate computations. If the input is null, the function returns null.

A common pattern is to subtract two datetime values to produce a duration, then pass it to Duration.TotalHours: Duration.TotalHours(endTime - startTime). The result is a decimal number, so 30 hours and 30 minutes returns 30.5.

For other total-duration conversions, use Duration.TotalDays, Duration.TotalMinutes, or Duration.TotalSeconds. Use Duration.ToRecord when you need the component breakdown (days, hours, minutes, seconds) rather than a cumulative total.

Examples

Example 1: Calculate total processing hours from log data

Table.AddColumn(
    Table.SelectColumns(
        Table.SelectRows(OrderLog, each [DurationMinutes] <> null),
        {"LogID", "DurationMinutes"}
    ),
    "TotalHours",
    each Duration.TotalHours(#duration(0, 0, [DurationMinutes], 0)),
    type number
)
Result
LogID
DurationMinutes
TotalHours
1L0021,72528.75
2L0042,74545.75
3L0061,06517.75
4L0082,67044.50

Example 2: Total hours for a mixed duration

#table(
    type table [Duration = duration, TotalHours = number],
    {{#duration(1, 6, 0, 0), Duration.TotalHours(#duration(1, 6, 0, 0))}}
)
Result
Duration
TotalHours
11.06:00:0030

Example 3: Compute elapsed hours between two datetime values

let
    Created = #datetime(2024, 1, 15, 9, 30, 0),
    Shipped = #datetime(2024, 1, 16, 14, 15, 0)
in
    #table(
        type table [Created = datetime, Shipped = datetime, ElapsedHours = number],
        {{Created, Shipped, Duration.TotalHours(Shipped - Created)}}
    )
Applied Steps

The final output — a single-row table showing both timestamps and the elapsed hours computed by Duration.TotalHours(Shipped - Created), which yields 28.75 hours.

Created
Shipped
ElapsedHours
11/15/2024 9:30:00 AM1/16/2024 2:15:00 PM28.75

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks