Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hellooo!
The dataset I'm currently using exports time such as 10m or 1h 30m or 2d 5h 45m etc...
I'm trying to convert this to a time type in PowerQuery but keep getting errors. Does anyone know how I can get Power BI to read this as 00:00:10 or 00:01:30 or 02:05:45 etc?
Solved! Go to Solution.
I think I got this working
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMsxQMDbIVYrVATLRaNMMBRNTqBCUBiuNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Time Spent" = _t]),
#"Lowercased Text" = Table.TransformColumns(Source,{{"Time Spent", Text.Lower, type text}}),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Lowercased Text", "Text Before Delimiter", each Text.BeforeDelimiter([Time Spent], "h ", {0, RelativePosition.FromEnd}), type text),
#"Inserted Last Characters" = Table.AddColumn(#"Inserted Text Before Delimiter", "Last Characters", each Text.End([Time Spent], 3), type text),
#"Replaced Value" = Table.ReplaceValue(#"Inserted Last Characters","m","",Replacer.ReplaceText,{"Last Characters"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","","0",Replacer.ReplaceValue,{"Text Before Delimiter"}),
#"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","","0",Replacer.ReplaceValue,{"Last Characters"}),
#"Inserted Merged Column" = Table.AddColumn(#"Replaced Value2", "Duration", each Text.Combine({[Text Before Delimiter], [Last Characters]}, ":"), type text),
#"Changed Type" = Table.TransformColumnTypes(#"Inserted Merged Column",{{"Duration", type duration}})
in
#"Changed Type"
Proud to be a Super User!
This is an interesting one @Anonymous
Can you display a small table to data please so we can see more examples of the data you are trying to convert?
Proud to be a Super User!
I think I got this working
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMsxQMDbIVYrVATLRaNMMBRNTqBCUBiuNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Time Spent" = _t]),
#"Lowercased Text" = Table.TransformColumns(Source,{{"Time Spent", Text.Lower, type text}}),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Lowercased Text", "Text Before Delimiter", each Text.BeforeDelimiter([Time Spent], "h ", {0, RelativePosition.FromEnd}), type text),
#"Inserted Last Characters" = Table.AddColumn(#"Inserted Text Before Delimiter", "Last Characters", each Text.End([Time Spent], 3), type text),
#"Replaced Value" = Table.ReplaceValue(#"Inserted Last Characters","m","",Replacer.ReplaceText,{"Last Characters"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","","0",Replacer.ReplaceValue,{"Text Before Delimiter"}),
#"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","","0",Replacer.ReplaceValue,{"Last Characters"}),
#"Inserted Merged Column" = Table.AddColumn(#"Replaced Value2", "Duration", each Text.Combine({[Text Before Delimiter], [Last Characters]}, ":"), type text),
#"Changed Type" = Table.TransformColumnTypes(#"Inserted Merged Column",{{"Duration", type duration}})
in
#"Changed Type"
Proud to be a Super User!
This was also a useful article I found
https://www.excelcampus.com/powerquery/convert-text-to-time-values-power-query/
Proud to be a Super User!
Thank you!!
No worries, I do love Power Query. I still can't believe I was using Excel for years without knowing about it haha!
Have a great day @Anonymous
Proud to be a Super User!
Do you really want time type or do you want duration?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
110 | |
91 | |
84 | |
66 |