REDUCE

Short answer

Collapse a list into one answer, step by step

REDUCE([initial_value], array, lambda(accumulator, value))
Excel version
2024+
Also searched as
apply list of replacements excel, multiple substitute one formula, find and replace table formula, compound growth rates excel, reduce lambda excel

What it returns

REDUCE starts from an initial value, steps through an array one item at a time, and applies a LAMBDA at each step. The LAMBDA takes the result so far and the next item, and returns the new result. REDUCE hands back only the final result.

That makes it the function for applying a list. A list of growth rates, compounded into one index. A list of find-and-replace rules, applied one after another to a column of text. Each step builds on the one before.

The result does not have to be a single number. If the initial value is a whole column, each step transforms the whole column and REDUCE returns the finished column as a spill. That is how one formula cleans every vendor name in a ledger extract.

Arguments that matter

ArgumentRequiredWhat it does
initial_valueYes, in practiceWhere the result starts. 1 for compounding, 0 for a sum, or the text column to be cleaned.
arrayYesThe list to step through. Rates, rule numbers, or any column of items.
lambdaYesA LAMBDA with two parameters: the result so far, then the current item. Returns the new result.

The initial value is where most mistakes start. Compounding from 0 returns 0, whatever the rates. Pick the value that leaves the first step unchanged: 1 for multiplication, 0 for addition, the raw text for cleanup.

The parameter order is fixed: accumulator first, current item second. Name them for what they hold, idx and growth, or txt and i.

In a financial model

The strongest case is a rules table. GL extracts arrive with vendor names that refuse to match: Acme Holdings Limited in one system, Acme Holdings Ltd in another. Someone keeps a list of the fixes. The old answer was a SUBSTITUTE nested inside another SUBSTITUTE, one layer per rule, which stops being readable around rule four and breaks the three levels of nesting play long before that.

REDUCE reads the rules from a Table instead. Add a row to the Table and the next recalculation applies it. The logic lives in one formula, and the rules live where a reviewer can read and own them.

That said, recurring cleanup of a large extract belongs upstream. The play on transform in Power Query, not in cells still applies. REDUCE fits the light case: a few thousand rows, a short rules list, a model without a query layer.

The second use is compounding a list of rates into an index: inflation by year, rent escalators, a curve of growth assumptions.

Worked example

A ledger extract on tab GL, a Table with a Vendor column. A rules Table on tab Rules, named Rules, with columns Find and Replace:

FindReplace
Limited Ltd
, Inc.(blank)
Corp. Corp

The cleaned vendor column, entered once beside the GL Table:

=REDUCE(GL[Vendor], SEQUENCE(ROWS(Rules)),
  LAMBDA(txt, i, SUBSTITUTE(txt, INDEX(Rules[Find], i), INDEX(Rules[Replace], i))))

SEQUENCE produces the rule numbers 1, 2, 3. At each step, REDUCE applies one rule to the whole vendor column and passes the result to the next.

Vendor (raw)Vendor (clean)
Acme Holdings LimitedAcme Holdings Ltd
Brightline, Inc.Brightline
Northwind Corp.Northwind Corp

A compounded escalator from yearly rates in Inputs!F15:J15:

=REDUCE(1, Inputs!F15:J15, LAMBDA(idx, growth, idx * (1 + growth)))

With 3%, 3%, 2.5%, 2.5% and 2% it returns about 1.137. PRODUCT(1+Inputs!F15:J15) returns the same and is plainer, so use it for pure compounding. REDUCE earns its place when a step needs logic, such as a cap or a floor on each year’s rate.

Old way vs new way

Nested SUBSTITUTE, one layer per rule, filled down a helper column:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B2, " Limited", " Ltd"), ", Inc.", ""), " Corp.", " Corp")

REDUCE reading the rules Table:

=REDUCE(GL[Vendor], SEQUENCE(ROWS(Rules)), LAMBDA(txt, i, SUBSTITUTE(txt, INDEX(Rules[Find], i), INDEX(Rules[Replace], i))))

The nested version hard-codes every rule and needs a new layer for each new one. The REDUCE version never changes. The rules Table does.

Where it breaks

REDUCE returns 0. The initial value is 0 and the LAMBDA multiplies. Zero times anything stays zero. Fix: start compounding from 1.

A rule leaves debris behind. Rules run in Table order. If Inc runs before , Inc., it strips the word and leaves Brightline,. for the later rule to miss. Fix: order rules from the longest and most specific to the shortest, and test the Table against a sample of real names.

Some names are not cleaned. SUBSTITUTE is case-sensitive, so a rule for Limited ignores LIMITED. Fix: add a rule per case variant, or switch the step to REGEXREPLACE, which can ignore case.

A new rule has no effect. The step list is fixed, such as SEQUENCE(3), or the rules sit in a plain range that new rows fall outside. Fix: keep the rules in a Table and count them with ROWS(Rules).

The answer is wrong and nothing errors. The LAMBDA parameters are in the wrong order. The first one always receives the running result, whatever you named it. Fix: put the accumulator first, and check one row by hand.

#SPILL! beside the ledger. REDUCE was entered inside the GL Table, or something blocks the cells below. Tables do not accept spills. Fix: put the formula in a plain range next to the Table and clear the spill area.

Every cell shows #NAME?. REDUCE needs Excel 2024 or Microsoft 365. Fix: for older versions, keep the nested SUBSTITUTE or move the cleanup into Power Query.

Related functions

  • SCAN. The same stepping, keeping every intermediate result. Use it when you need the path, such as a monthly balance, not the end point.
  • LAMBDA. The step logic. Name a cleanup rule set and call it from several tabs.
  • SEQUENCE. Generates the rule numbers that REDUCE steps through.
  • REGEXREPLACE. One pattern can replace several literal rules. Combine them: REDUCE over a Table of patterns.
  • VSTACK. Inside REDUCE, it stacks a block of rows at each step, which builds one table from a list of sources.
  • Read raw data stays raw. The cleaned column sits beside the extract. It never overwrites it.

All functions