Duration.FromText

Duration

Converts a text representation to 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.FromText(text as nullable text) as nullable duration

Parameters

NameTypeRequiredDescription
texttextYesA text string representing a duration in the format "D.HH:MM:SS" or "HH:MM:SS" (e.g., "1.02:30:00" for 1 day, 2 hours, 30 minutes).

Return Value

durationA duration value parsed from the given text, or null if the input is null.

Remarks

Duration.FromText parses a text value in the format "D.HH:MM:SS" (days, hours, minutes, seconds) or "HH:MM:SS" (when days are zero) into a duration value. This is the inverse of Duration.ToText. The day component (the D. prefix) is optional and may be omitted for durations shorter than one day. Fractional seconds are also supported.

If the text is null, the function returns null. If the text cannot be parsed — for example, it contains an unexpected format or non-numeric characters — the function raises an error. Use try Duration.FromText(...) otherwise null to handle malformed data without stopping the query.

A typical source of text-format durations is systems that serialize duration values to string for storage or transport (such as ISO 8601 PTxHxMxS strings — note that M uses its own D.HH:MM:SS format, not ISO 8601). You will need to reformat ISO 8601 duration strings before passing them to Duration.FromText.

Examples

Example 1: Parse duration text values in M format

#table(
    type table [DurationText = text, Parsed = duration],
    {
        {"1.04:45:00", Duration.FromText("1.04:45:00")},
        {"1.21:45:00", Duration.FromText("1.21:45:00")},
        {"00:15:30",   Duration.FromText("00:15:30")}
    }
)
Result
DurationText
Parsed
11.04:45:001.04:45:00
21.21:45:001.21:45:00
300:15:300.00:15:30

Example 2: Parse a specific duration text value

#table(
    type table [DurationText = text, Parsed = duration],
    {{"1.02:30:00", Duration.FromText("1.02:30:00")}}
)
Result
DurationText
Parsed
11.02:30:001.02:30:00

Example 3: Safe parsing with try...otherwise for mixed data

#table(
    type table [DurationText = text, Parsed = duration],
    {
        {"1.04:45:00", try Duration.FromText("1.04:45:00") otherwise null},
        {"invalid",    try Duration.FromText("invalid") otherwise null},
        {"0.17:45:00", try Duration.FromText("0.17:45:00") otherwise null}
    }
)
Result
DurationText
Parsed
11.04:45:001.04:45:00
2invalidnull
30.17:45:000.17:45:00

Compatibility

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