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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
aaron797
Advocate I
Advocate I

Convert ss.xxx to mm.ss.xxx

How do you convert ss.xxx to mm:ss:xxx in query editor?

For example, my data is coming in like 229.19, i can convert this to 0.00:03:49.190000 using #duration.

 

#duration(0,0,0,[Cumulative_Time])

 

However i would like a solution that doesn't include days and hours, and rounds to nearest 3 decimals.

I am trying to achieve "03:49.190"

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @aaron797 ,

 

To my knowledge, Duration type in Power Query does not support various format as you expected.

You could use Duration.Minutes() and Duration.Seconds() and then combine them to get the format as mm:ss.xxx.

Duration.Minutes().PNGDuration.Seconds().PNG

combine minutes and seconds.PNG

 

The final output is shown below: (But it should be noted that the final data type of the column is Text.)

new duration format.gif

 

Here is the whole M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjKy1DO0VIrViVYyNzDQMzZRio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Cumulative_Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Cumulative_Time", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Duration", each #duration(0,0,0,[Cumulative_Time])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Minute", each Number.ToText( Duration.Minutes([Duration]),"0#")),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Second", each Number.ToText( Duration.Seconds([Duration]),"##.000")),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "New Format", each [Minute]&":"&[Second]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Minute", "Second"})
in
    #"Removed Columns"

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @aaron797 ,

 

To my knowledge, Duration type in Power Query does not support various format as you expected.

You could use Duration.Minutes() and Duration.Seconds() and then combine them to get the format as mm:ss.xxx.

Duration.Minutes().PNGDuration.Seconds().PNG

combine minutes and seconds.PNG

 

The final output is shown below: (But it should be noted that the final data type of the column is Text.)

new duration format.gif

 

Here is the whole M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjKy1DO0VIrViVYyNzDQMzZRio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Cumulative_Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Cumulative_Time", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Duration", each #duration(0,0,0,[Cumulative_Time])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Minute", each Number.ToText( Duration.Minutes([Duration]),"0#")),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Second", each Number.ToText( Duration.Seconds([Duration]),"##.000")),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "New Format", each [Minute]&":"&[Second]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Minute", "Second"})
in
    #"Removed Columns"

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mahoneypat
Employee
Employee

You can wrap your #duration with Duration.TotalMinutes to get minutes as a decimal.  A good practice is to store durations as a decimal number and then use custom format strings to display it how you want once you've done any math.

 

mahoneypat_0-1622981831826.png

 

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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