Duration.Hours

Duration

Returns the hours component from a duration value.

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

Syntax

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

Parameters

NameTypeRequiredDescription
durationdurationYesThe duration value to extract the hours component from.

Return Value

numberThe hours component (0 through 23).

Remarks

Duration.Hours returns the hours component (0 through 23) from a duration value. This is the hour portion after removing whole days, not the total hours. If the input is null, the function returns null.

Examples

Example 1: Extract hours from OrderLog durations

Table.AddColumn(
    Table.SelectColumns(
        Table.SelectRows(
            OrderLog,
            each [DurationMinutes] <> null
        ),
        {"LogID", "DurationMinutes"}
    ),
    "Hours",
    each Duration.Hours(#duration(0, 0, [DurationMinutes], 0)),
    Int64.Type
)
Result
LogID
DurationMinutes
Hours
1L0021,7254
2L0042,74521
3L0061,06517
4L0082,67020

Example 2: Extract hours from a scalar duration

#table(
    type table [Duration = duration, Hours = number],
    {{#duration(2, 14, 30, 0), Duration.Hours(#duration(2, 14, 30, 0))}}
)
Result
Duration
Hours
12.14:30:0014

Compatibility

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