List.Accumulate
Walks a list from start to end and carries a running value along, item by item.
Group: List. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
List.Accumulate(list as list, seed as any, accumulator as function) as any
| Parameter | Type | Description |
|---|---|---|
list | list | The items to walk through. |
seed | any | The running value before the first item. |
accumulator | function | A function of the running value and the current item, (state, current) => ..., that gives the next running value. |
Returns
any. The running value after the last item; the seed for an empty list.
Remarks
- The running value can be anything: a number, a text, a record or a table.
Examples
A running total
List.Accumulate({120, 80, 45.5}, 0, (state, current) => state + current)
245.5
A balance with yearly interest
1 000 kroner, then 5, 3 and 4 percent interest.
List.Accumulate({5, 3, 4}, 1000, (balance, rate) => Number.Round(balance * (1 + rate / 100), 2))
1124.76