Duration.ToText is a Power Query M function that converts duration values into a readable textual representation, adopting the pattern “day.hour:mins:sec”.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Duration.ToText( duration as nullable duration, optional format as nullable text, ) as nullable text
The Duration.ToText function transforms a duration value into a string. Its output is in a user-friendly format, namely “day.hour:mins:sec”. In other words, it changes durations into a text format that’s easy to read and interpret.
duration: This represents the duration that needs to be converted into a textual representation.
format: This is an optional parameter. However, it’s important to note that this parameter is deprecated and will produce an error if it’s not null.
To understand the utility of the Duration.ToText function, let’s look at a couple of practical examples.
Consider you have a duration value of
#duration( 1, 4, 29, 08 ). Here’s how you can transform it into a text value:
Duration.ToText( #duration( 1, 4, 29, 08 ) ) // Output: "1.04:29:08"
What’s more, the function doesn’t discriminate based on the size of the duration value. It can work its charm on larger duration values too. For instance:
Duration.ToText( #duration( 111, 10, 0, 59 ) ) // Output: "111.10:00:59"
As seen above, the Duration.ToText function successfully converts a longer duration of 111 days, 10 hours, 0 minutes, and 59 seconds into a neat text format.
And that’s all there is to turning a duration into text so you can easily incorporate it in a bigger string.
Other functions related to Duration.ToText are: