Been struggling for a few hours to reach my goal.
The objective is to use a list with the column names to aggregate when using Table. Group instead of having a fix list of columns.
I've defined already GroupColumns as a list for the "key" and it works well.
Example:
=
Table.Group(
Source,
GroupColumns,
{{
"Sales (M€)", each List.Sum([#"Sales (M€)"]), type number},
{"Sales (Qty MU)", each List.Sum([#"Sales (Qty MU)"]), type number}
})
I have defined a list named SumColumns:
SumColumns = {"Sales (M€)","Sales (Qty MU)"}
Now I can't find the syntax to create a list that would dynamically create all the columns I want based on the SumColumns list.
I assumed I would get the answer here but I don't understand the "LocalContext" part: How do I properly use table.group in a PowerQuery query to dynamically summarize different rows and columns?
I tried this:
= Table.Group(
Source,
{GroupColumns},
{{
SumColumns,
(LocalContext) => List.Sum(Table.Column(LocalContext, SumColumns)),
type number
}}
)
But I get the error "cannot convert a value of type List to type Text"
I tried going through "unpivot" to do the trick, but I get the same issue when I want to pivot back the attribute to columns, and it would be much slower anyway.
Any ideas?
Thanks
Aurelien