Reputation: 53
Convert a text from minutes:seconds to datatype time
I have a column with time (running time) in format (h:)mm:ss how can i convert this to a datatype "time" because given functions always expect the hours which i most of the time not have.
i've tried duration.FromText but the input format doesnot apply. Nor the automatic Time parse... it fails on the mm:ss part. = Table.AddColumn(#"Added Custom", "Parse", each Time.From(DateTimeZone.From([Tijd])), type time) gives a lot of errors
Upvotes: 0
Views: 1384
Reputation: 13460
You didn't showed how your data looks like, so I will assume each value can be one of these:
In this case, one thing you can do, is to re-format the data, before changing its type. Add a custom column like this:
if List.Count(Text.PositionOf([Time], ":", Occurrence.All)) = 0 then
"0:00:" & Text.End("0" & [Time], 2)
else if List.Count(Text.PositionOf([Time], ":", Occurrence.All)) = 1 then
"0:" & Text.End("0" & [Time], 5)
else
[Time]
which will count how many times :
occurs in the input string (using Text.PositionOf and List.Count), and add suitable prefix (taking care for the leading zeroes with Text.End):
Now you can change the data type of the newly added column to Duration
or Time
.
Upvotes: 2