Duration.TotalHours
DurationReturns the total duration expressed as a fractional number of hours.
Syntax
Duration.TotalHours(duration as nullable duration) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
duration | duration | Yes | A duration value. |
Return Value
number — The 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
)LogID | DurationMinutes | TotalHours | |
|---|---|---|---|
| 1 | L002 | 1,725 | 28.75 |
| 2 | L004 | 2,745 | 45.75 |
| 3 | L006 | 1,065 | 17.75 |
| 4 | L008 | 2,670 | 44.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))}}
)Duration | TotalHours | |
|---|---|---|
| 1 | 1.06:00:00 | 30 |
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)}}
)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 | |
|---|---|---|---|
| 1 | 1/15/2024 9:30:00 AM | 1/16/2024 2:15:00 PM | 28.75 |