Downloads
Power Query MDurationIntermediate

Duration.From

Converts a number to a duration, where the number is read as days.

Syntax
Duration.From(value as any) as nullable duration

Returns: The duration, or null when the input is null.

What it does

Duration.From turns a plain number into a duration. A number is read as days, so 2 becomes two days. Source systems often store a lead time, a term or a delay as a plain number of days, and Duration.From gives that number the duration type, so the other duration functions can be used on it.

Syntax and arguments

Example

A supplier scorecard holds each supplier's quoted lead time as a number of days. The purchasing team converts the lead time into hours, which their service level report uses.

let
    Suppliers = #table(type table [Supplier = text, LeadDays = number],
        {{"Acme Supply Co", 2}, {"Blue Harbor LLC", 5}}),
    AsDuration = Table.AddColumn(Suppliers, "LeadTime", each Duration.From([LeadDays]), type duration),
    Hours = Table.AddColumn(AsDuration, "LeadHours", each Duration.TotalHours([LeadTime]), type number)
in
    Hours

Two days is 48 hours, and five days is 120 hours. The scorecard can now compare the lead times with the hours each supplier actually took.

Example: a second, different use

Use a days value from an ERP export as a duration, then take its whole days with Duration.Days to check the value.

Things to watch

In business terms

Lead times, payment terms and cycle times often arrive from source systems as plain numbers. Converting them to durations lets the report work on them with the same rules as dates, so the scorecard and the contract use the same definitions.

Related functions

All Power Query M functions · View as Markdown · M basics