Forum Discussion
AnonymeC
1 year agoRegular Visitor
[Help needed] Group by several columns without selecting individually 1 by 1
Hi everyone, My aim is very simple yet somehow I couldn't find the ressources to do this task, I was hoping you could help me. So my goal is to do a simple group by for all the columns in my ...
- 1 year ago
Hi AnonymeC
let
Source = YourSource,
UnPivot = Table.UnpivotOtherColumns(Source, {"Code"}, "Attribute", "Value"),
Pivot = Table.Pivot(UnPivot, List.Distinct(UnPivot[Attribute]), "Attribute", "Value", List.Sum)
in
Pivotor
let
Source = YourSource,
Group = Table.Group(Source, {"Code"},
List.Transform(
List.Skip(Table.ColumnNames(Source)),
each {_, Expression.Evaluate("each List.Sum(["& _ &"])", #shared), type number } ) )
in
GroupStéphane
ronrsnfld
1 year agoSuper User
Please provide a representative data sample (preferably as text which can be copy/pasted, or a link to a file) along with expected data output from that sample.
It is not clear to me exactly what you want to do and the above will be helpful. In general:
- Create a list of the column names you wish to aggregate starting with Table.ColumnNames(#"Previous Step") and applying some selection criteria.
- Programmatically create a list of your aggregation argument lines (probably using List.Transform).
- Use that created list as an argument to the Table.Group function
Again, depending on your expected output, you might apply that list to the List.Accumulate, List.Generate, or a recursive function.