cancel
Showing results for
Did you mean:
Regular Visitor

## Convert String to Duration

Hi All,

I just wanted to ask for help on how to convert the Time to first response: Elapsed column, with type string, to duration by still containing the __h __m format?

The business users prefer to sort this column by still seeing the same format but can't since it is in string type. I tried doing things on my end but it is having errors as it does not display those with greater than 24h.

Would greatly appreciate your help.

Thanks.

1 ACCEPTED SOLUTION
Super User

=Duration.From(Expression.Evaluate(List.Accumulate({{"h","/24+0"},{"m","/1440"}},[#"Time to first response: Elapsed"],(x,y)=>Text.Replace(x,y{0},y{1}))))

2 REPLIES 2
Super User

=Duration.From(Expression.Evaluate(List.Accumulate({{"h","/24+0"},{"m","/1440"}},[#"Time to first response: Elapsed"],(x,y)=>Text.Replace(x,y{0},y{1}))))

Solution Sage

You can add a custom column in the query editor with this expression (replace ElapsedTime with your actual column name). Once that creates a duration column, it will convert to a decimal # when you load it. Take a look at this article for how to then calculate your measures and format it at the end to show as hours and minutes.

Calculate and Format Durations in DAX – Hoosier BI

=#duration(0, Number.FromText(Text.BeforeDelimiter([ElapsedTime], "h")), Number.FromText(Text.BetweenDelimiters([ElapsedTime], " ", "m")), 0)

Pat

Microsoft Employee

Announcements

#### 2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

#### Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

#### Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

#### Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors