How to Accumulate a Result with REDUCE in Excel
REDUCE walks through a list carrying a running value, so you can apply rules step by step and get one final answer.
You will learn to
- Accumulate a running value from a starting point
- Skip steps that break a rule
- Simulate a policy such as automatic reordering
How it works
REDUCE(initial_value, array, LAMBDA(accumulator, value, calculation)) starts with the initial value, then visits each item of the array. The LAMBDA returns the new accumulator each time, and REDUCE returns the final one: =REDUCE(E2,B2:B8,LAMBDA(stock,m,stock+m)) gives closing stock from an opening balance and a list of movements.
The power is that each step can depend on the running total so far. =REDUCE(E2,B2:B8,LAMBDA(s,m,IF(s+m<0,s,s+m))) skips any order that would take stock below zero — something a plain SUM cannot do.
=REDUCE(E2,B2:B8,LAMBDA(stock,m,stock+m))