Forum Discussion
Data text to time convet
- 5 years ago
Hi, Firewtc343
As is suggested by primolee , the format of the text can not be parsed correctly by 'Time.FromText'. I'd like to suggest you manually parse the text. I created data to reprodce your scenario. The pbix file is attached in the end.
Table:
You may add two new steps with the following steps.
= Table.TransformColumns(#"Changed Type",{"PTTTIM",each let txt = _, l = Text.Length(_), res = if l=1 then "00:00:0"&txt else if l=2 then "00:00:"&txt else if l=3 then "00:0"&Text.Start(txt,1)&":"&Text.End(txt,2) else if l=4 then "00:"&Text.Start(txt,2)&":"&Text.End(txt,2) else if l=5 then "0"&Text.Start(txt,1)&":"&Text.Middle(txt,1,2)&":"&Text.End(txt,2) else if l=6 then Text.Start(txt,2)&":"&Text.Middle(txt,2,2)&":"&Text.End(txt,2) else null in res } ), = Table.TransformColumnTypes(Custom1,{{"PTTTIM", type time}})Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, Firewtc343
As is suggested by primolee , the format of the text can not be parsed correctly by 'Time.FromText'. I'd like to suggest you manually parse the text. I created data to reprodce your scenario. The pbix file is attached in the end.
Table:
You may add two new steps with the following steps.
= Table.TransformColumns(#"Changed Type",{"PTTTIM",each
let
txt = _,
l = Text.Length(_),
res =
if l=1 then "00:00:0"&txt
else if l=2 then "00:00:"&txt
else if l=3 then "00:0"&Text.Start(txt,1)&":"&Text.End(txt,2)
else if l=4 then "00:"&Text.Start(txt,2)&":"&Text.End(txt,2)
else if l=5 then "0"&Text.Start(txt,1)&":"&Text.Middle(txt,1,2)&":"&Text.End(txt,2)
else if l=6 then Text.Start(txt,2)&":"&Text.Middle(txt,2,2)&":"&Text.End(txt,2)
else null
in
res
}
),
= Table.TransformColumnTypes(Custom1,{{"PTTTIM", type time}})
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you very much.