Excel Function: REDUCE

The REDUCE function reduces an array to a cumulative value by applying a LAMBDA function.

Prerequisite: understand the LAMBDA function.

Usage:

=REDUCE(initial_value, array, LAMBDA)


Example of use

The goal here is to create the equivalent of a SUM function:

excel sum reduce

Enter the REDUCE function followed by the initial value of the accumulator (0, to start calculating the sum from 0):

=REDUCE(0

Then enter the range of cells that contains the values to accumulate:

=REDUCE(0,B2:B9

Add the LAMBDA function then choose the name of the variable for the accumulation of values (total) and the one for the current value (score):

=REDUCE(0,B2:B9,LAMBDA(total,score

And finally, enter the useful formula for this simple addition:

=REDUCE(0,B2:B9,LAMBDA(total,score,total+score))

The REDUCE function will then start with a total of 0, go through the scores of the array B2:B9 and add each score to the total.

And to finish, the REDUCE function will return the final total (the accumulation of all the values of the array B2:B9):

excel functions reduce lambda

This is a simple sum, but to push this example a little further, we could add even numbers and subtract odd numbers.

In this case, you would need to add the IF and ISEVEN functions to the formula:

=REDUCE(0,B2:B6,LAMBDA(total,score,total+IF(ISEVEN(score),score,-score)))
excel functions reduce lambda if
If needed, you can download the Excel file used here: reduce.xlsx
Note: this function is only available with Office 365.