Forum Discussion

juan jimenez's avatar
juan jimenez
Iron Contributor
Jan 22, 2020
Solved

power query and time format

Hi   Some moths ago i managed to get help in order to change a list of time data expressed like:   1502 1515 15 25   1532 1542 1544 1550 1562 16 45 1702 17 06 ...
  • SergeiBaklan's avatar
    Jan 22, 2020

    juan jimenez 

    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])

Resources