我想使用函数 Table.Group 在 Power Query 中创建动态分组依据
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}}),
但是列出我需要从源表生成的聚合列。我可以得到 3 个列表:
ColumnNames = Table.ColumnNames(Source),
ColumnTypes = Table.Schema(Source)[TypeName],
ColumnFx = List.Max (type of function may differ based on column data type)
要创建聚合列列表,我需要生成类似的列表
aggCols = {ColumnNames{0}, ColumnFx{0}, ColumnTypes{0}} (I know it is nonsense in this format)
在另一种语言中,我会使用循环,但在我看来,使用 M 是不可能的。
样本输入:
name col1 col2
n1 name11 1
n1 name12 2
n1 name13 3
n2 name21 4
n2 name22 5
n3 name32 6
样本输出:
name col1 col2
n1 name13 6
n2 name22 9
n3 name32 6
有任何想法吗?