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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors