Duration.ToRecord

Duration

Returns a record with Days, Hours, Minutes, and Seconds fields 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.ToRecord(duration as duration) as record

Parameters

NameTypeRequiredDescription
durationdurationYesA duration value to decompose into its components.

Return Value

recordA 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"}
)
Result
LogID
DurationMinutes
Days
Hours
Minutes
Seconds
1L0021,72514450
2L0042,745121450
3L0061,065017450
4L0082,670120300

Example 2: Decompose a specific duration

Duration.ToRecord(#duration(3, 5, 30, 0))
Result
Field
Value
1Days3
2Hours5
3Minutes30
4Seconds0

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
)
Result
LogID
DurationMinutes
DurationLabel
1L0021,7251d 4h 45m
2L0042,7451d 21h 45m
3L0061,0650d 17h 45m
4L0082,6701d 20h 30m

Compatibility

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