Duration.ToRecord
DurationReturns a record with Days, Hours, Minutes, and Seconds fields from a duration value.
Syntax
Duration.ToRecord(duration as duration) as recordParameters
| Name | Type | Required | Description |
|---|---|---|---|
duration | duration | Yes | A duration value to decompose into its components. |
Return Value
record — A record with fields Days, Hours, Minutes, and Seconds as numbers.
Remarks
Duration.ToRecord decomposes a duration value into a record with four numeric fields: Days, Hours, Minutes, and Seconds. Each field represents only its own component of the duration, not a cumulative total. For example, a duration of 1 day and 2.5 hours returns [Days=1, Hours=2, Minutes=30, Seconds=0], not [Hours=26, ...]. Use Table.ExpandRecordColumn to expand the resulting record into separate table columns.
This is distinct from the Duration.Total* functions (Duration.TotalHours, Duration.TotalMinutes, Duration.TotalSeconds), which return the entire duration expressed as a single fractional number in the specified unit. Use Duration.ToRecord when you need a breakdown of components for display or formatting; use Duration.Total* when you need a numeric value for arithmetic or comparison.
Field names in the returned record are always Days, Hours, Minutes, and Seconds (capitalized), which you must reference exactly when expanding with Table.ExpandRecordColumn.
Examples
Example 1: Expand duration components into separate columns
Table.ExpandRecordColumn(
Table.AddColumn(
Table.SelectColumns(
Table.SelectRows(OrderLog, each [DurationMinutes] <> null),
{"LogID", "DurationMinutes"}
),
"Parts",
each Duration.ToRecord(#duration(0, 0, [DurationMinutes], 0))
),
"Parts",
{"Days", "Hours", "Minutes", "Seconds"}
)LogID | DurationMinutes | Days | Hours | Minutes | Seconds | |
|---|---|---|---|---|---|---|
| 1 | L002 | 1,725 | 1 | 4 | 45 | 0 |
| 2 | L004 | 2,745 | 1 | 21 | 45 | 0 |
| 3 | L006 | 1,065 | 0 | 17 | 45 | 0 |
| 4 | L008 | 2,670 | 1 | 20 | 30 | 0 |
Example 2: Decompose a specific duration
Duration.ToRecord(#duration(3, 5, 30, 0))Field | Value | |
|---|---|---|
| 1 | Days | 3 |
| 2 | Hours | 5 |
| 3 | Minutes | 30 |
| 4 | Seconds | 0 |
Example 3: Build a human-readable duration label from record fields
Table.AddColumn(
Table.SelectColumns(
Table.SelectRows(OrderLog, each [DurationMinutes] <> null),
{"LogID", "DurationMinutes"}
),
"DurationLabel",
each
let r = Duration.ToRecord(#duration(0, 0, [DurationMinutes], 0))
in Text.From(r[Days]) & "d " & Text.From(r[Hours]) & "h " & Text.From(r[Minutes]) & "m",
type text
)LogID | DurationMinutes | DurationLabel | |
|---|---|---|---|
| 1 | L002 | 1,725 | 1d 4h 45m |
| 2 | L004 | 2,745 | 1d 21h 45m |
| 3 | L006 | 1,065 | 0d 17h 45m |
| 4 | L008 | 2,670 | 1d 20h 30m |