Forum Discussion

AriB's avatar
AriB
New Member
2 years ago
Solved

Conditional sum in nested table

Hey you guys,   I'm awfully new to Power Query and M code, and need help with a problem that I cannot seem to tackle however many solved forum threads and tutorials I may browse...   I have a Gro...
  • OwenAuger's avatar
    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