#duration

Duration

Creates a duration value from days, hours, minutes, and seconds components.

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

Syntax

#duration(days as number, hours as number, minutes as number, seconds as number) as duration

Parameters

NameTypeRequiredDescription
daysnumberYesThe number of days in the duration.
hoursnumberYesThe number of hours (added to the days component).
minutesnumberYesThe number of minutes (added to the hours component).
secondsnumberYesThe number of seconds (can include fractional seconds).

Return Value

durationA duration value representing the specified span of time.

Remarks

#duration is M's literal constructor for creating duration values — a span of time expressed as days, hours, minutes, and seconds.

All four arguments are additive and can be fractional. The total duration is the sum of all components: days * 86400 + hours * 3600 + minutes * 60 + seconds seconds.

Durations are most commonly obtained by subtracting two dates or datetimes of the same type. #duration lets you construct a specific span inline, useful for date arithmetic: adding 30 days (#duration(30, 0, 0, 0)), or representing a time interval.

Duration is not a number — you cannot multiply a duration by a scalar directly. Use Duration.TotalDays to convert to a number first, or Duration.From to construct from a total.

Examples

Example 1: Create a duration literal (1 day, 2 hours, 30 minutes)

#duration(1, 2, 30, 0)
Result
Result
1P1DT2H30M

Example 2: Add a duration to a date

#date(2024, 1, 1) + #duration(30, 0, 0, 0)
Result
Result
11/31/2024

Example 3: Extract total hours from a duration

let
    d = #duration(1, 6, 0, 0)
in
    Duration.TotalHours(d)
Result
Result
130

Compatibility

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