List.Accumulate Function (Power Query M)

List.Accumulate walks through a list one item at a time and builds up a single result from it, like a running total or a combined string.

If you want to boil a whole list down to one value, a sum, a product, the largest number, a joined string, this is the function that does it in a single step.

Syntax of List.Accumulate Function

List.Accumulate(list as list, seed as any, accumulator as function) as any

where

  • list (required, list). The list you want to walk through, one item at a time.
  • seed (required, any). The starting value before any item is processed. Its type decides the type of the final result.
  • accumulator (required, function). A function of the form (state, current) => ... that runs once per item. state is the result so far, current is the item being processed, and whatever it returns becomes the new state.

Returns: whatever the accumulator builds up. It can be a number, text, a list, or a record. On an empty list, it returns the seed unchanged.

In plain terms, you give it a starting value and a rule, and it applies that rule to each item in turn, carrying the running result forward until the list is done.

Example 1: Sum a list of numbers

Add up every number in a list, starting from 0.

let
Source = List.Accumulate({8, 15, 22, 5}, 0, (state, current) => state + current)
in
Source

Result: 50

The seed is 0, and each item is added to the running state, so 0 + 8 + 15 + 22 + 5 gives 50.

Example 2: Multiply a list into one product

To multiply instead of add, start the seed at 1 and use * in the accumulator.

let
Source = List.Accumulate({2, 3, 4, 5}, 1, (state, current) => state * current)
in
Source

Result: 120

The seed has to be 1 here. Starting at 0 would multiply everything down to 0.

Example 3: Join text with a separator

Combine a list of text values into one string, with a - between each piece.

let
Source = List.Accumulate({"Sales", "Q1", "Report"}, "", (state, current) => if state = "" then current else state & "-" & current)
in
Source

Result: Sales-Q1-Report

The if state = "" check handles the first item, so the result does not start with a stray -. For a simpler way to combine text in Power Query, Text.Combine is usually the better fit.

Example 4: Find the largest number in a list

Carry the bigger of the running state and the current item forward each time.

let
Source = List.Accumulate({34, 12, 88, 47, 61}, 0, (state, current) => List.Max({state, current}))
in
Source

Result: 88

This works only when the list has no values below the seed of 0. For lists that may contain negatives, seed with the first item instead, or use a dedicated approach to find the maximum value in Power Query.

Example 5: Count items above a threshold

Add 1 to the running count whenever an item clears the threshold of 50.

let
Source = List.Accumulate({34, 12, 88, 47, 61}, 0, (state, current) => if current > 50 then state + 1 else state)
in
Source

Result: 2

Only 88 and 61 are above 50, so the count lands at 2. You can swap in any test here, including a text check with Text.Contains, to count items that match a condition.

Example 6: Total a column from a table

Say you have an Invoices table and you want the total of the Amount column.

Here is the starting data:

ClientAmount
Acme120
Globex340
Initech95
Umbrella510

Pull the column into a list with Table.Column, then accumulate it:

let
Source = Excel.CurrentWorkbook(){[Name="Invoices"]}[Content],
Amounts = Table.Column(Source, "Amount"),
Total = List.Accumulate(Amounts, 0, (state, current) => state + current)
in
Total

Result: 1065

The Amount values are added one by one, so 120 + 340 + 95 + 510 gives 1065.

Example 7: Accumulate the min and max at once

The seed can be a record, which lets you build up more than one value in a single pass. Here the seed tracks both the smallest and largest number seen so far.

let
Source = List.Accumulate({1, 49, -400, 150, 60}, [Min = null, Max = null], (state, current) => [Min = (if state[Min] = null or current < state[Min] then current else state[Min]), Max = (if state[Max] = null or current > state[Max] then current else state[Max])])
in
Source

Result: [Min=-400, Max=150]

The accumulator returns a record each pass, so state carries both fields forward. The null checks set the first values, then each item updates Min or Max as needed.

Things to keep in mind with List.Accumulate

  • It is the reduce/fold function in Power Query. If you have met reduce or fold in other languages, this is the same idea: collapse a list into one value.
  • Watch the leading-separator trap when joining text. Without a first-item check, state & "-" & current puts a stray separator at the front. Guard it with if state = "" then current else ... (Example 3).
  • There is no early exit. Once the running state is settled, List.Accumulate still walks every remaining item, so it can’t stop short the way a List.First or a folded filter would. For “does any item match” checks, List.Contains or List.AnyTrue is faster.

Performance and query folding

List.Accumulate runs in memory and does not fold to the source, so the whole list is pulled in before it runs. For a plain sum or count, List.Sum or List.Count is clearer and just as fast. Reach for List.Accumulate when you need custom step-by-step logic those helpers can’t express.

Common questions about List.Accumulate

List.Accumulate vs List.Sum, which should I use?

Use List.Sum for a straight total. It reads better and needs no accumulator. Use List.Accumulate when the running logic is more than addition, like a product, a conditional count, or building a record.

Can List.Accumulate build a running total?

Not on its own. It returns a single final value, not the value at each step. For a per-row running total you usually add an index column and reference earlier rows instead.

List of All Power Query Functions

Related Power Query Functions / Articles:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.