Forum Discussion
Duration with format H S
- Anonymous5 years ago
Hi Anonymous ,
According to my understanding, you want to convert the text in format of (xxHxxM) to Duration type, right?
Please try to change the original value to seconds(Hour *3600 + Minute *60) ,the whole M syntax is shown below:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsshQitWJVjI0zTC1yAUzjYwzTE0RTHME0wTBNIAyTTJgQoYGcFml2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Duration = _t]), #"Replaced Value" = Table.ReplaceValue(Source,"h"," ",Replacer.ReplaceText,{"Duration"}), #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","m","",Replacer.ReplaceText,{"Duration"}), #"Split Column by Delimiter" = Table.SplitColumn(#"Replaced Value1", "Duration", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Duration.1", "Duration.2"}), #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Duration.1", Int64.Type}, {"Duration.2", Int64.Type}}), #"Replaced Value2" = Table.ReplaceValue(#"Changed Type",null,0,Replacer.ReplaceValue,{"Duration.2"}), #"Renamed Columns" = Table.RenameColumns(#"Replaced Value2",{{"Duration.1", "Hour"}, {"Duration.2", "Minute"}}), #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Duration", each #duration(0,0,0,[Hour]*3600 +([Minute]+0)*60)), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Hour", "Minute"}), #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Duration", type duration}}) in #"Changed Type1"Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
Check this existing thread for this:
Thanks,
Pragati
Is not exactly that , I have for example for one day and 57 minutes, this is the format
24H57m
- Pragati115 years ago
Super User
Hi Anonymous ,
Can you share some sample data in that case whic can be easily copied?
Thanks,
Pragati
- Anonymous5 years agoNot applicable
8 h 15 h 58 m 23 h 55 m 23 h 57 m 23 h 54 m 23 h 54 m 23 h 50 m 24 h 24 h 23 h 10 m 24 h 24 h 23 h 55 m 23 h 58 m
Sorry but i don“t know how to paste a table