Forum Discussion
Help! Converting decimal to date/time format string doesnt always work
- 4 years ago
miguelsus2000 I would do this in Power Query if possible, looks like your Day is wrong, which is causing the problems with the other calculations. I've followed the same logic as you though. I'm curious why that Day value is wrong though - can you provide a sample file or more context?
Paste this code into a new blank Query in Power Query editor and see if it makes sense/does the trick:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LcxBCgAgCETRu7iOwTStziLe/xqBuXswn4mgCVbKESTgW2AYFwx+CgqRnrpRbG/o/vGE2z8S3EWZDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [AccTimeInStep = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"AccTimeInStep", type number}}),
#"Inserted Days" = Table.AddColumn(#"Changed Type", "Days", each Number.RoundDown([AccTimeInStep]), Int64.Type),
#"Inserted Remaining Hours" = Table.AddColumn(#"Inserted Days", "Remaining Hours", each ([AccTimeInStep] - [Days])*24, type number),
#"Inserted Hours" = Table.AddColumn(#"Inserted Remaining Hours", "Hours", each Number.RoundDown([Remaining Hours]), Int64.Type),
#"Inserted Remaining Minutes" = Table.AddColumn(#"Inserted Hours", "Remaining Minutes", each ([Remaining Hours] - [Hours])*60, type number),
#"Inserted Minutes" = Table.AddColumn(#"Inserted Remaining Minutes", "Minutes", each Number.RoundDown([Remaining Minutes]), Int64.Type),
#"Inserted Remaining Seconds" = Table.AddColumn(#"Inserted Minutes", "Remaining Seconds", each ([Remaining Minutes] - [Minutes])*60, type number),
#"Inserted Seconds" = Table.AddColumn(#"Inserted Remaining Seconds", "Seconds", each Number.RoundDown([Remaining Seconds]), Int64.Type),
#"Inserted TimeKey" = Table.AddColumn(#"Inserted Seconds", "TimeKey", each ([Days] * 1000000) + ([Hours] * 10000) + ([Minutes] * 100) + [Seconds], type number),
#"Split Column by Position" = Table.SplitColumn(Table.TransformColumnTypes(#"Inserted TimeKey", {{"TimeKey", type text}}, "en-NZ"), "TimeKey", Splitter.SplitTextByPositions({0,2,4,6}, true), {"D", "HH", "MM", "SS"}),
#"Replaced Value" = Table.ReplaceValue(#"Split Column by Position","","0",Replacer.ReplaceValue,{"D"}),
#"Merged Columns" = Table.CombineColumns(#"Replaced Value",{"D", "HH", "MM", "SS"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"D:HH:MM:SS")
in
#"Merged Columns"
miguelsus2000 I would do this in Power Query if possible, looks like your Day is wrong, which is causing the problems with the other calculations. I've followed the same logic as you though. I'm curious why that Day value is wrong though - can you provide a sample file or more context?
Paste this code into a new blank Query in Power Query editor and see if it makes sense/does the trick:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LcxBCgAgCETRu7iOwTStziLe/xqBuXswn4mgCVbKESTgW2AYFwx+CgqRnrpRbG/o/vGE2z8S3EWZDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [AccTimeInStep = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"AccTimeInStep", type number}}),
#"Inserted Days" = Table.AddColumn(#"Changed Type", "Days", each Number.RoundDown([AccTimeInStep]), Int64.Type),
#"Inserted Remaining Hours" = Table.AddColumn(#"Inserted Days", "Remaining Hours", each ([AccTimeInStep] - [Days])*24, type number),
#"Inserted Hours" = Table.AddColumn(#"Inserted Remaining Hours", "Hours", each Number.RoundDown([Remaining Hours]), Int64.Type),
#"Inserted Remaining Minutes" = Table.AddColumn(#"Inserted Hours", "Remaining Minutes", each ([Remaining Hours] - [Hours])*60, type number),
#"Inserted Minutes" = Table.AddColumn(#"Inserted Remaining Minutes", "Minutes", each Number.RoundDown([Remaining Minutes]), Int64.Type),
#"Inserted Remaining Seconds" = Table.AddColumn(#"Inserted Minutes", "Remaining Seconds", each ([Remaining Minutes] - [Minutes])*60, type number),
#"Inserted Seconds" = Table.AddColumn(#"Inserted Remaining Seconds", "Seconds", each Number.RoundDown([Remaining Seconds]), Int64.Type),
#"Inserted TimeKey" = Table.AddColumn(#"Inserted Seconds", "TimeKey", each ([Days] * 1000000) + ([Hours] * 10000) + ([Minutes] * 100) + [Seconds], type number),
#"Split Column by Position" = Table.SplitColumn(Table.TransformColumnTypes(#"Inserted TimeKey", {{"TimeKey", type text}}, "en-NZ"), "TimeKey", Splitter.SplitTextByPositions({0,2,4,6}, true), {"D", "HH", "MM", "SS"}),
#"Replaced Value" = Table.ReplaceValue(#"Split Column by Position","","0",Replacer.ReplaceValue,{"D"}),
#"Merged Columns" = Table.CombineColumns(#"Replaced Value",{"D", "HH", "MM", "SS"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"D:HH:MM:SS")
in
#"Merged Columns"