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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jmeccles
Helper I
Helper I

How to Convert Text (HH:MM:SS) to Duration in Power Query

Hi there!

I'm trying to change a text column [with entries in the format HH:MM:SS - see "Resolution Time (in Hrs)" in screenshot] of my report into a duration column but I'm unsure of how to.
Duration Transformation InaccessibleDuration Transformation InaccessibleI hoped that the Duration transformation could assist but it doesn't appear to be accessible.

Any ideas on how I could go about doing this?

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

Hi, @jmeccles 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

You may add a new step with the following m codes.

= Table.TransformColumns(#"Changed Type",{"Resolution Time",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
}
)

 

Result:

b2.png

 

Best Regards

Allan

 

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

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @jmeccles 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

You may add a new step with the following m codes.

= Table.TransformColumns(#"Changed Type",{"Resolution Time",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
}
)

 

Result:

b2.png

 

Best Regards

Allan

 

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

`#duration` will handle the math. This is cleaner:

DurationHHMMSS = each let d = List.Transform(Text.Split(_, ":"), Number.FromText) in #duration(0, d{0}, d{1}, d{2}),
TransformedTable = Table.TransformColumns(Source, {ColumnName, DurationHHMMSS, type duration}),
pedrovr2020
Frequent Visitor

hola aqui hay un video tal vez te da alguna idea

https://youtu.be/DQDBB_0E9xQ?t=2

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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