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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

How to convert hrs in string to duration

I am trying to convert a column type string to duration and tried doing my own research to do it, but I have failed. 

 

This is the column I am needing to convert. 

 

PwBIDummy_0-1656520587412.png

 

This is the M code I am using. 

 

 

 

= Table.TransformColumns(#"Changed Type",{"Resolution Time (in Hrs)",each 
let txt=_,
h=Number.From( Text.Start(txt,2)),
mm=Number.From( Text.Middle(txt,3,2)),
ss=Number.From( Text.End(txt,2)),
dd=Number.IntegerDivide(h,24),
hh=Number.Mod(h,24)
in 
#duration(dd,hh,mm,ss),
type duration
}
)

 

 

 

 

Here are the results 

PwBIDummy_1-1656520699545.png

I believe I am getting the errors because of the 3 digit hours, but I do not understand or know how to do a range for the start.text or if that is even how I should approach this. 

 

Please help! 

1 REPLY 1
HotChilli
Super User
Super User

You can use Text.BeforeDelimiter,  .AfterDeli... , .BetweenDelim... for this.

--

A slightly easier way might be to Split the column on ":" and then add a custom column to construct the desired result , for example, #duration(0,1stCol, 2ndCol, 3rdCol) 

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.