List.Accumulate
ListAccumulates a result by applying a function to each item in a list, starting from an initial seed value.
Syntax
List.Accumulate(list as list, seed as any, accumulator as function) as anyParameters
| Name | Type | Required | Description |
|---|---|---|---|
list | list | Yes | The list of items to process. |
seed | any | Yes | The initial value to start accumulating from. |
accumulator | function | Yes | A function (state, current) => newState that combines each item with the accumulated state. |
Return Value
any — The final accumulated value after processing all items in the list.
Remarks
List.Accumulate is M's "reduce" or "fold" function. It processes each item in a list sequentially, carrying forward a state value that gets updated by the accumulator function. The final state is returned.
This is one of the most powerful list functions — it can implement running totals, string building, multi-step replacements, and any logic that requires carrying state across items.
Examples
Example 1: Sum quantities manually
let
Quantities = Table.Column(Sales, "Quantity"),
Total = List.Accumulate(Quantities, 0, (state, current) => state + current)
in
#table({"TotalQuantity"}, {{Total}})Result
TotalQuantity | |
|---|---|
| 1 | 35 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks