Forum Discussion
Conditional sum in nested table
- 2 years ago
Hi AriB
Table.AggregateTableColumn acts on only a single column within the nested table, so it can't apply a filter to any columns other than the one being aggregated.
Instead, try this, which filters the nested table with Table.TransformColumns before applying Table.AggregateTableColumn.
#"Création colonne quotité" = Table.DuplicateColumn( #"Calcul du nombre d'affectations", "Agent", "Qtité Occ." ), #"Calcul de la quotité" = Table.AggregateTableColumn( Table.TransformColumns( #"Création colonne quotité", {"Qtité Occ.", each Table.SelectRows(_, each [Affecté] = 1)} ), "Qtité Occ.", {{"Qté Occ.", List.Sum, "Qté Occ."}} )You could also write it this way with a separate step "Filter nested table" applying Table.TransformColumns:
#"Création colonne quotité" = Table.DuplicateColumn( #"Calcul du nombre d'affectations", "Agent", "Qtité Occ." ), #"Filter nested table" = Table.TransformColumns( #"Création colonne quotité", {"Qtité Occ.", each Table.SelectRows(_, each [Affecté] = 1)} ), #"Calcul de la quotité" = Table.AggregateTableColumn( #"Filter nested table", "Qtité Occ.", {{"Qté Occ.", List.Sum, "Qté Occ."}} )Do these work for you?
Regards
AriB Glad it worked 🙂
Yes, in fact Table.TransformColumns can transform multiple columns in one step.
I used a short-hand syntax since we were transforming just one column.
In general , you can provide a list of transformations, where each transformation is specificed by a list of the form:
{ "Column Name", TransformationFunction, type }
There are some other optional arguments as well.
https://learn.microsoft.com/en-us/powerquery-m/table-transformcolumns
Regards