Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
ngc8164
Regular Visitor

Convert Duration to Hours and Minutes

In Power Query, how do I convert a duration to total hours & minutes.
For example 252.14:19:26.4230000 becomes 6062:19 and 42.07:02:28.9700000 becomes 1015:02

 

Many Thanks

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use this in a custom column

= Text.From(Number.IntegerDivide(Duration.TotalHours([Time]),1)) & ":" & Text.PadStart(Text.From(Number.Round(60*Number.Mod(Duration.TotalHours([Time]),1),0)),2,"0")

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI10jM0sTK0tDIy0zMxMjYAAqVYnWglEyM9A3MrAyMrIws9S3MDiHgsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type duration}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.From(Number.IntegerDivide(Duration.TotalHours([Time]),1)) & ":" & Text.PadStart(Text.From(Number.Round(60*Number.Mod(Duration.TotalHours([Time]),1),0)),2,"0"))
in
    #"Added Custom"

View solution in original post

2 REPLIES 2
ngc8164
Regular Visitor

Thanks very much Vijay. I made a slight adjustement to get exactly what I needed.

Vijay_A_Verma
Super User
Super User

Use this in a custom column

= Text.From(Number.IntegerDivide(Duration.TotalHours([Time]),1)) & ":" & Text.PadStart(Text.From(Number.Round(60*Number.Mod(Duration.TotalHours([Time]),1),0)),2,"0")

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI10jM0sTK0tDIy0zMxMjYAAqVYnWglEyM9A3MrAyMrIws9S3MDiHgsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type duration}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.From(Number.IntegerDivide(Duration.TotalHours([Time]),1)) & ":" & Text.PadStart(Text.From(Number.Round(60*Number.Mod(Duration.TotalHours([Time]),1),0)),2,"0"))
in
    #"Added Custom"

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.