Yesterday I wrote about how to calculate a running total (cumulative total) using Power Query. This used List.FirstN and the Index to select the elements to sum.

A similar challenge is calculating a sum based on conditions (SUMIF) if the condition is Index <= current value then this degenerates to the Running Total case.

The process builds on the running total case but the list that is to be summed is generated by Table.SelectRows. Values from the current record can be injected into this query by use of the “let – in” structure. This is analogous to a correlated subquery in SQL.