Duration.Hours
DurationReturns the hours component from a duration value.
Syntax
Duration.Hours(duration as nullable duration) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
duration | duration | Yes | The duration value to extract the hours component from. |
Return Value
number — The 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 | |
|---|---|---|---|
| 1 | L002 | 1,725 | 4 |
| 2 | L004 | 2,745 | 21 |
| 3 | L006 | 1,065 | 17 |
| 4 | L008 | 2,670 | 20 |
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 | |
|---|---|---|
| 1 | 2.14:30:00 | 14 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks