I want to create dynamic Group By in Power Query with function Table.Group
Table.Group(table as table, key as any, aggregatedColumns as list, optional groupKind as nullable number, optional comparer as nullable function) as table
#"Grouped Rows" = Table.Group(Source, {"name"},
{{"col1", each List.Max([col1]), type text}, //I used here max for simplification (otherwise text concat)
{"col2", each List.Sum([col1]), type number}}),
However list aggregatedColumns I need to generate from Source table. I can get 3 lists:
ColumnNames = Table.ColumnNames(Source),
ColumnTypes = Table.Schema(Source)[TypeName],
ColumnFx = List.Max (type of function may differ based on column data type)
To create aggregatedColumns list I would need to generate list like
aggCols = {ColumnNames{0}, ColumnFx{0}, ColumnTypes{0}} (I know it is nonsense in this format)
In another language I would use loop for it but with M it seems to me not possible.
sample input:
name col1 col2
n1 name11 1
n1 name12 2
n1 name13 3
n2 name21 4
n2 name22 5
n3 name32 6
sample output:
name col1 col2
n1 name13 6
n2 name22 9
n3 name32 6
Any ideas?