Forum Discussion
power query and time format
- Jan 22, 2020
Another variant, and if more close to the formula you used in Excel
the script is
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], TrimmText = Table.TransformColumns( Table.TransformColumnTypes( Source, {{"A", type text}}, "en-GB" ), {{"A", Text.Trim, type text}} ), CleanText = Table.TransformColumns( Table.TransformColumnTypes( TrimmText, {{"A", type text}}, "en-GB" ), {{"A", Text.Clean, type text}} ), ConvertToTime = Table.ReplaceValue( CleanText, each [A] , each Time.FromText( Text.Start([A],2) & Text.End([A],2) ), Replacer.ReplaceValue,{"A"} ) in ConvertToTimeIf source data is more clean that could be simply = Time.FromText([A])
I see, thank you.
Power Query converts 4 characters text into the time, it has no guess what it could be if less characters. I's add each value with zeros if it less than 4 characters:
= Table.ReplaceValue(#"Tipo cambiado1",each [Column1.1], each Text.PadEnd([Column1.1],4,"0"),Replacer.ReplaceText,{"Column1.1"})
As for 2400 Power Query doesn't recognise it as correct time, actually that is 00:00 next day. We may consider that as the bug or as feature, but that's what we have. Thus we may replace 2400 on 0000, or on 23:59 to have more or less correct result
= Table.ReplaceValue(#"Replaced Value","2400","2359",Replacer.ReplaceText,{"Column1.1"})
Please check in attached file, source file location is to be adjusted.
Would it be possible to add each value with zeros if it less than 4 characters, but the zero at the end?
If you added it at the end, 9am, would be 90:00 instead of 09:00
thank you again.
- SergeiBaklanJan 26, 2020Diamond Contributor
I guess you mean to add zeros in front of text, it's more logical. With that 900 will be 0900. When it hall be Text.PadStart instead of Text.PadEnd
= Table.ReplaceValue(#"Tipo cambiado1",each [Column1.1], each Text.PadStart([Column1.1],4,"0"),Replacer.ReplaceText,{"Column1.1"})- juan jimenezJan 27, 2020Iron Contributor
it works! tx
Can you also help me to divide a column by ITS FIRST COMMA (",")?
#"Dividir columna por delimitador" = Table.SplitColumn(#"Valor reemplazado83", "Column1", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Column1.1", "Column1.2", "Column1.3"}),This is because I sometimes get lines with more than the expected first coma
1220, XXX.aaa.bbb.ccc.ddd,eee
I would like just to divide the column in the beginning by the first comma (",") appearing.
Thanks, juan
- SergeiBaklanJan 27, 2020Diamond Contributor
Juan, splitting the column just select Left-most delimiter instead of default "each occurrence"
Result is