Summarizing of columns in Power Query is not as easy as you would expect, but List.Accumulate function can be useful here.

List.Accumulate goes row by row and does some operation, like adding.

For example here weˇd like to have total prices in a new column.

Create custom column and write this:

  • =List.Accumulate(
       Animals[Price],
       0,
       (state, current) => state + current)

Because:

  •  Animals[Price] – name of M step (usually the previous one) and column to summarize 
       0, – base, to which we are going to add (if it is 0, then the summarizing goes from 0)
       (state, current) => state + current) – declares, that we are summarizing

List.Accumulate can be similarly used for another operations. For example this syntax puts together text strings:

Leave a Reply

Your email address will not be published.

*

clear formPost comment