Forum Discussion

Berean_50's avatar
Berean_50
Icon for Helper I rankHelper I
4 years ago
Solved

How to group rows dynamically

Given the following input: the goal is to produce the following output where the table is grouped by the static columns Name and Period. The challenging aspect of this task is that Category A,...
  • AlexisOlson's avatar
    4 years ago

    How about this?

     

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        DynamicColumns = List.RemoveItems(Table.ColumnNames(Source), {"Name", "Period"}),
        #"Grouped Rows" = Table.Group(Source, {"Name", "Period"},
            List.Transform(DynamicColumns, (col) => {col, each List.Max(Table.Column(_, col)), type text}))
    in
        #"Grouped Rows"

     

    This takes the column names other than "Name" and "Period" and maxes over them in a Group By step.