Forum Discussion

cricks's avatar
cricks
Frequent Visitor
6 years ago
Solved

Multiple date/time columns

I'm trying to work with Excel data that is grouped by date/time. There can be multiple groups, each with their own DateTime column. Each group will have a different start time and interval, and a var...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi all,

     

    I did it slightly differently:

    let
        Source = myTable,
        Columns =  List.Buffer(List.Accumulate(Table.ColumnNames(Source), {}, (s, a)=> if Text.StartsWith(a,"DateTime") then s & {{a}} else List.RemoveLastN(s,1) & {List.Last(s) & {a}} )),
        Output = Table.Combine(List.Accumulate(Columns, {}, (s, a) => s & {Table.UnpivotOtherColumns(Table.RenameColumns(Table.SelectColumns(Source, a), {a{0}, "DateTime"}) , {"DateTime"}, "Attribute", "Value")}))
    in
        Output

    The code above first split the columns into groups and then unpivot and combine group-by-group.

    Column groups list is buffered, but this can be removed the number of columns is quite large.

     

    Kind regards,

    John