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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Convert Text time to minutes "1 Hour 30 minutes" to 90 minutes

Hey Team,

 

I have a column called "Time worked" which looks like this:

ykaleel_0-1612320771743.png

 

I would like to convert to a number to calculate average time spent. 

 

Example:

2 Hours 38 minutes -> 158 minutes

23 minutes -> 23 minutes

2 Hours 8 minutes -> 128 minutes.

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

you can use this formula for new column. There are probably a better method out to do it, but it will work 🙂

let 
       CreateListHoursMinutes = List.Select(Text.SplitAny([Column1],"Hoursminutes "), each _ <> ""),
       CreateMinutes = if List.Count(CreateListHoursMinutes)= 1 then CreateListHoursMinutes{0}& " minutes" else Text.From(Number.From(CreateListHoursMinutes{0})*60 + Number.From(CreateListHoursMinutes{1})) & " minutes"
    in 
        CreateMinutes

Here the complete example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLwyC8tKlYwtlDIzcwrLUktVorVAQobo3KhqpAUxQIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let 
       CreateListHoursMinutes = List.Select(Text.SplitAny([Column1],"Hoursminutes "), each _ <> ""),
       CreateMinutes = if List.Count(CreateListHoursMinutes)= 1 then CreateListHoursMinutes{0}& " minutes" else Text.From(Number.From(CreateListHoursMinutes{0})*60 + Number.From(CreateListHoursMinutes{1})) & " minutes"
    in 
        CreateMinutes)
in
    #"Added Custom"

 

Jimmy801_0-1612335394074.png

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

 

 

 

Table.AddColumn(#"Added Custom", "minutes", each Expression.Evaluate(Text.Replace(Text.Replace([Column1], " Hours ","*60+"), "minutes","")))

 

OR

 

 Table.AddColumn(#"Added Custom", "minutes", each Expression.Evaluate(Text.BeforeDelimiter(Text.Replace([Column1], " Hours ","*60+"), "minutes")))

 

smpa01
Super User
Super User

@Anonymouscan you please try this

//custom function called qx
let   fx=(input)=>
    Web.Page(
        "<script>
            var str = '"&input&"';
            var res = str.match(/\d+/gm);                      
            document.write(res);
        </script>") {0}[Data]{0}[Children]{1}[Children]{0}[Text]
in
    fx
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLIyC8tKlYwtlDIzcwrLUktVorVAQobo3IVPMCq4IoUlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each qx([Column1])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Text.Split([Custom],",")),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Count", each List.Count([Custom.1])),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Custom.2", each Text.From(if [Count]=2 then (Number.From([Custom.1]{0})*60)+Number.From([Custom.1]{1}) else [Custom.1]{0})&" "&"minutes"),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Custom", "Custom.1", "Count"})
in
    #"Removed Columns"

Capture.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

you can use this formula for new column. There are probably a better method out to do it, but it will work 🙂

let 
       CreateListHoursMinutes = List.Select(Text.SplitAny([Column1],"Hoursminutes "), each _ <> ""),
       CreateMinutes = if List.Count(CreateListHoursMinutes)= 1 then CreateListHoursMinutes{0}& " minutes" else Text.From(Number.From(CreateListHoursMinutes{0})*60 + Number.From(CreateListHoursMinutes{1})) & " minutes"
    in 
        CreateMinutes

Here the complete example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLwyC8tKlYwtlDIzcwrLUktVorVAQobo3KhqpAUxQIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let 
       CreateListHoursMinutes = List.Select(Text.SplitAny([Column1],"Hoursminutes "), each _ <> ""),
       CreateMinutes = if List.Count(CreateListHoursMinutes)= 1 then CreateListHoursMinutes{0}& " minutes" else Text.From(Number.From(CreateListHoursMinutes{0})*60 + Number.From(CreateListHoursMinutes{1})) & " minutes"
    in 
        CreateMinutes)
in
    #"Added Custom"

 

Jimmy801_0-1612335394074.png

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.