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])
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
ConvertToTime
If source data is more clean that could be simply = Time.FromText([A])
- juan jimenezJan 25, 2020Iron Contributor
Thanks!!!
I am learning a lot.
Enclosed please find my version of your suggestions and the source data (normally comes in a .txt file but as this web does not accept txt files i have converted into xls).
I still have problems with 1 digit single AM times. look on the 215 and also with 24:00
Can you help me with these 2 errors?
Thank you again
- SergeiBaklanJan 25, 2020Diamond Contributor
You are welcome.
Sorry, but I didn't find the source file. Query takes data from horario.txt which was not attached.
- juan jimenezJan 25, 2020Iron ContributorI think i attached an excel file called horario.xlsx as txt is not accepted