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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
saud968
Super User
Super User

Text to duration format

I am try to convert a text type column to duration format as"h:mm:ss". I am using the DAX as below, however, I am getting correct output for value 1h 2m 3s as 1:02:03, however, for 11m 20s I get 0:00:20

Formatted AHT =

VAR AHTText = support__cw_ops_manage_case_merge_temp[AHT Text]

VAR HoursText = IFERROR(VALUE(LEFT(AHTText, FIND("h", AHTText) - 1)), 0)

VAR MinutesText = IFERROR(

    IF(

        ISNUMBER(FIND("m", AHTText)),

        VALUE(MID(AHTText, FIND("h", AHTText) + 2, FIND("m", AHTText) - FIND("h", AHTText) - 2)),

        VALUE(MID(AHTText, FIND("h", AHTText) + 2, LEN(AHTText) - FIND("h", AHTText) - 1))

    ),

    0

)

VAR SecondsText = IFERROR(

    IF(

        ISNUMBER(FIND("s", AHTText)),

        VALUE(MID(AHTText, FIND("m", AHTText) + 2, FIND("s", AHTText) - FIND("m", AHTText) - 2)),

        VALUE(MID(AHTText, FIND("m", AHTText) + 2, LEN(AHTText) - FIND("m", AHTText) - 1))

    ),

    0

)

RETURN FORMAT(TIME(HoursText, MinutesText, SecondsText), "h:mm:ss")

saud968_0-1701253966495.png

 

@lbendlin @Ahmedx 

 

2 ACCEPTED SOLUTIONS

FormattedAHT = //Try this one in Calculated column
VAR AHTText = support__cw_ops_manage_case_merge_temp[AHT Text]
VAR HoursText = IFERROR(VALUE(LEFT(AHTText, FIND("h", AHTText & "h") - 1)), 0)
VAR MinutesStartPos = IFERROR(FIND("h", AHTText) + 2, 1)
VAR MinutesEndPos = IFERROR(FIND("m", AHTText & "m", MinutesStartPos), LEN(AHTText))
VAR MinutesText = VALUE(MID(AHTText, MinutesStartPos, MinutesEndPos - MinutesStartPos))
VAR SecondsStartPos = IFERROR(FIND("m", AHTText) + 2, 1)
VAR SecondsEndPos = IFERROR(FIND("s", AHTText & "s", SecondsStartPos), LEN(AHTText))
VAR SecondsText = VALUE(MID(AHTText, SecondsStartPos, SecondsEndPos - SecondsStartPos))
RETURN FORMAT(TIME(HoursText, MinutesText, SecondsText), "h:mm:ss")

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



View solution in original post

FormattedAHT = // Analyze yourself please 
VAR AHTText = support__cw_ops_manage_case_merge_temp[AHT Text]
VAR HoursText = IFERROR(VALUE(LEFT(AHTText, FIND("h", AHTText & "h") - 1)), 0)
VAR MinutesStartPos = IFERROR(FIND("h", AHTText) + 2, 1)
VAR MinutesEndPos = IFERROR(FIND("m", AHTText & "m", MinutesStartPos), LEN(AHTText))
VAR MinutesText = IFERROR(VALUE(MID(AHTText, MinutesStartPos, MinutesEndPos - MinutesStartPos)), 0)
VAR SecondsStartPos = IFERROR(FIND("m", AHTText) + 2, 1)
VAR SecondsEndPos = IFERROR(FIND("s", AHTText & "s", SecondsStartPos), LEN(AHTText))
VAR SecondsText = IFERROR(VALUE(MID(AHTText, SecondsStartPos, SecondsEndPos - SecondsStartPos)), 0)
RETURN FORMAT(TIME(HoursText, MinutesText, SecondsText), "h:mm:ss")

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



View solution in original post

5 REPLIES 5
mh2587
Super User
Super User

 

FormattedAHT = //Try this Calculated Column might help you
VAR AHTText = support__cw_ops_manage_case_merge_temp[AHT Text]
VAR HoursText = IFERROR(VALUE(LEFT(AHTText, FIND("h", AHTText) - 1)), 0)
VAR MinutesStartPos = IF(ISNUMBER(FIND("h", AHTText)), FIND("h", AHTText) + 2, 1)
VAR MinutesEndPos = IFERROR(FIND("m", AHTText), LEN(AHTText))
VAR MinutesText = VALUE(MID(AHTText, MinutesStartPos, MinutesEndPos - MinutesStartPos))
VAR SecondsStartPos = IF(ISNUMBER(FIND("m", AHTText)), FIND("m", AHTText) + 2, 1)
VAR SecondsEndPos = IFERROR(FIND("s", AHTText), LEN(AHTText))
VAR SecondsText = VALUE(MID(AHTText, SecondsStartPos, SecondsEndPos - SecondsStartPos))
RETURN FORMAT(TIME(HoursText, MinutesText, SecondsText), "h:mm:ss")

 


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Getting the below error 

saud968_0-1701256458683.png

 

FormattedAHT = //Try this one in Calculated column
VAR AHTText = support__cw_ops_manage_case_merge_temp[AHT Text]
VAR HoursText = IFERROR(VALUE(LEFT(AHTText, FIND("h", AHTText & "h") - 1)), 0)
VAR MinutesStartPos = IFERROR(FIND("h", AHTText) + 2, 1)
VAR MinutesEndPos = IFERROR(FIND("m", AHTText & "m", MinutesStartPos), LEN(AHTText))
VAR MinutesText = VALUE(MID(AHTText, MinutesStartPos, MinutesEndPos - MinutesStartPos))
VAR SecondsStartPos = IFERROR(FIND("m", AHTText) + 2, 1)
VAR SecondsEndPos = IFERROR(FIND("s", AHTText & "s", SecondsStartPos), LEN(AHTText))
VAR SecondsText = VALUE(MID(AHTText, SecondsStartPos, SecondsEndPos - SecondsStartPos))
RETURN FORMAT(TIME(HoursText, MinutesText, SecondsText), "h:mm:ss")

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



saud968_0-1701257666330.png

Now this error

FormattedAHT = // Analyze yourself please 
VAR AHTText = support__cw_ops_manage_case_merge_temp[AHT Text]
VAR HoursText = IFERROR(VALUE(LEFT(AHTText, FIND("h", AHTText & "h") - 1)), 0)
VAR MinutesStartPos = IFERROR(FIND("h", AHTText) + 2, 1)
VAR MinutesEndPos = IFERROR(FIND("m", AHTText & "m", MinutesStartPos), LEN(AHTText))
VAR MinutesText = IFERROR(VALUE(MID(AHTText, MinutesStartPos, MinutesEndPos - MinutesStartPos)), 0)
VAR SecondsStartPos = IFERROR(FIND("m", AHTText) + 2, 1)
VAR SecondsEndPos = IFERROR(FIND("s", AHTText & "s", SecondsStartPos), LEN(AHTText))
VAR SecondsText = IFERROR(VALUE(MID(AHTText, SecondsStartPos, SecondsEndPos - SecondsStartPos)), 0)
RETURN FORMAT(TIME(HoursText, MinutesText, SecondsText), "h:mm:ss")

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors