Home » excel » excel – Power Query Table.Group List.Sum(two columns)

excel – Power Query Table.Group List.Sum(two columns)

Posted by: admin May 14, 2020 Leave a comment

Questions:

Trying to figure out how to perform the sum of two columns inside a Table.Group step.

This one throws:

Expression.Error: We cannot convert Type to List type.

M Code:

= Table.Group(PreviousStep, {"PF"}, {{"ColumnName", each List.Sum({[Column1], [Column2]})}, type number})

M Gurus: Is this even possible?

Objective: Simplify steps (actually I have 12 columns I want to reduce to 6 – adding pairs, grouping them, all in one simple step)

How to&Answers:

You can kind of do it if you create a custom column to sum within that step. Something like this:

= Table.Group(
      PreviousStep,
      {"PF"},
      {{"ColumnName",
        each List.Sum(
                 Table.AddColumn(
                     _,
                     "Custom", each [Column1] + [Column2]
                 )[Custom]
             ),
        type number
      }}
 )