Hi @sam.mckay,
I’m writing a simple function in PQ which is meant to transform a string in the format “2 01:40:00” in 49:40:00, or “12:30:00” in “12:30:00”.
Essentially if the string is formed by 2 tokens separated by a space the first is the number of days that has to be converted in hours and summed up to the hours of the second token. If only 1 token (12:30:00) no action.
There is some automatic thing going on when I try to run it, but I cannot understand where I’m wrong.
Thanks for your valuable support
Roberto
Expression.Error: We cannot convert the value #time(12, 12, 13) to type Text.
Details:
Value=12:12:13 PM
Type=[Type]
= (TimeString as text) as text =>
let
Tokens = Text.Split(TimeString, " "),
ConvertedDayInHours = if List.Count(Tokens) = 1 then 0 else Number.FromText(Tokens{0}) * 24,
HMS = Text.Split(Tokens{1}, ":"),
Hours = HMS{0},
Minutes = HMS{1},
Seconds = HMS{2},
Result = Text.Combine( Number.ToText( Number.FromText(Hours) + ConvertedDayInHours ), Minutes, Seconds, ":")
in
Result
TimeTransformation.pbix (13.8 KB)