Excel functions / Logical

REDUCE function

Boils an array down to one result by running a function on a running value and each item in turn.

Syntax

=REDUCE(initial_value, array, lambda)

Arguments

When to use it

REDUCE runs a LAMBDA over a range one value at a time, carrying a running result from each step to the next, and gives the final result. It can build anything a loop would: a total with special rules, a joined text, a count of pairs.

Examples

  1. Add up only the even numbers

    ABC
    1Value
    2318
    38
    45
    510

    In C2: =REDUCE(0, A2:A5, LAMBDA(total, x, IF(ISEVEN(x), total+x, total))) → 18

    Try this example

  2. Join items with arrows

    ABC
    1Item
    2PenStart > Pen > Stapler > Folder
    3Stapler
    4Folder
    5Tape
    6Glue
    7Ruler

    In C2: =REDUCE("Start", A2:A4, LAMBDA(path, x, path & " > " & x)) → Start > Pen > Stapler > Folder

    Try this example

Common mistakes

Try REDUCE in the playground

Practise it

Related functions