Logical functions
REDUCE
Matches all 16 recorded answers
Recorded: 16 workbook cells. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | REDUCE |
| Bulgarian | REDUCE |
| Czech | REDUCE |
| Danish | REDUCE |
| German | REDUCE |
| Greek | REDUCE |
| English (Australia) | REDUCE |
| English (United Kingdom) | REDUCE |
| English (United States) | REDUCE |
| Spanish | REDUCE |
| Estonian | REDUCE |
| Finnish | REDUCE |
| French | REDUCE |
| Hebrew | REDUCE |
| Croatian | REDUCE |
| Hungarian | REDUCE |
| Indonesian | REDUCE |
| Italian | REDUCE |
| Japanese | REDUCE |
| Korean | REDUCE |
| Lithuanian | REDUCE |
| Latvian | REDUCE |
| Norwegian | REDUCE |
| Dutch | REDUCEREN |
| Polish | REDUCE |
| Portuguese (Brazil) | REDUZIR |
| Portuguese (Portugal) | REDUCE |
| Romanian | REDUCE |
| Russian | REDUCE |
| Slovak | REDUCE |
| Slovenian | REDUCE |
| Serbian (Latin) | SMANJITI |
| Swedish | REDUCE |
| Thai | REDUCE |
| Turkish | REDUCE |
| Ukrainian | REDUCE |
| Vietnamese | REDUCE |
| Chinese (Simplified) | REDUCE |
| Chinese (Hong Kong) | REDUCE |
| Chinese (Traditional) | REDUCE |
Names from Microsoft's support site.
What it does
REDUCE(initial_value, array, lambda)
REDUCE folds an array into a single value by threading an accumulator through it, one cell at
a time.
The rule:
- The accumulator starts at
initial_value. - The array is enumerated in row-major order.
- For each cell, the callable is invoked with two arguments — the current accumulator and the cell's value — and its result becomes the new accumulator.
- When the enumeration ends, the accumulator is the result.
Order matters here in a way it does not for MAP, BYROW, or BYCOL, and for two distinct
reasons:
- Semantically, because the callable need not be associative or commutative. Building a delimited string, or subtracting each element in turn, gives different answers under a different order.
- Numerically, because floating-point addition is not associative. A left fold over an array of
doubles is a specific summation algorithm with a specific error behaviour, and it is not the same
algorithm
SUMuses.REDUCE(0, range, LAMBDA(a,v,a+v))andSUM(range)are not required to agree in the last bits, and expecting them to is a mistake worth naming explicitly.
Arguments
REDUCE(initial_value, array, lambda)
initial_value— required. The accumulator's starting value. It is the first argument, not the last, which is the position most easily misremembered.array— required. The values to fold over.lambda— required, and always third. It takes exactly two parameters, in the order(accumulator, value).
The commonly misunderstood positions are the first argument and the callable's parameter order.
Swapping (accumulator, value) for (value, accumulator) produces a lambda that runs without
complaint and computes something else.
Try it
Quirks
Result and edge cases
Returns a single value of whatever kind the last invocation produced. Unlike the other helpers on
this shelf, REDUCE does not return an array.
- Empty array. With nothing to fold,
initial_valueshould be the answer. This is the degenerate case most likely to differ between implementations and is unverified here. - Single-cell array. One invocation.
- Accumulator kind changes mid-fold. Nothing forbids it: a fold that starts with a number and concatenates text will have a text accumulator after the first step. The callable is responsible for coherence.
- Errors in the array. Delivered to the callable as ordinary argument values. Whether the fold continues past an error depends entirely on what the callable returns.
- Accumulator becomes an error. It is threaded onward like any other value unless the callable handles it, so one bad cell typically poisons the whole result — usually the desired behaviour, occasionally a surprise.
How to implement
Notes for implementers
- Thread the accumulator by value and accept it before preparing the next argument. Preparing several argument slices ahead of time is the natural optimisation and it is incorrect here.
- Do not assume the accumulator's kind is stable. Typing the fold to the initial value's kind will fail on the first callable that changes it.
- State the empty-array answer. Returning
initial_valueis the mathematically obvious choice; make it explicit rather than falling out of a loop that never ran. - A fast path for all-numeric arrays must produce identical results to the general path, including the order of operations — otherwise the optimisation is observable.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.
REDUCE · 1 lines · calc-func/src/catalogue/lambda_helpers.rs on GitHub2 reduce_fn "REDUCE" (3, 3) [R "initial_value", R "array", R "lambda"] resume reduce_resume => reduce_start; |s, a, sv| { run(s, reduce_start(s, a, sv), sv) }
reduce_start · 7 lines · calc-func/src/catalogue/lambda_helpers.rs on GitHubfn reduce_start(
site: &Site<'_>,
a: &[CalcValue],
sv: &mut EvalServices<'_>,
) -> Step<Box<dyn KernelTask>> {
reduce_task(site, a, sv, false)
}
Kernels shared with other functions
preparedcatalogue/lambda_helperslambdacatalogue/lambda_helpersitemcatalogue/lambda_helperscellcatalogue/lambda_helpersitemscatalogue/lambda_helpersarraycatalogue/lambda_helpersreduce_taskcatalogue/lambda_helpershelpercatalogue/lambda_helpersHelperTask::advancecatalogue/lambda_helpersruncatalogue/lambda_helpers
Argument and result plumbing
No implementation has been published with a Handbook test suite for this function.
Version differences
No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.
Alternatives
Relationships
SCANisREDUCEthat keeps every intermediate accumulator instead of only the last, and returns an array shaped like the input. If you want to see the running total rather than the total,SCANis the function.MAPtransforms without accumulating;BYROWandBYCOLreduce along one axis.REDUCEis the only member of the set that collapses everything to one value.SUM,PRODUCT,CONCAT,TEXTJOINare the built-in folds. Prefer them when they fit: they are faster and, forSUM, their summation behaviour is the one the rest of the workbook assumes.LAMBDAsupplies the callable; recursion via a named lambda is the alternative route to iteration, andREDUCEis usually the clearer one.- Readers confuse
REDUCEwithMAP(accumulating versus transforming) and withSCAN(final versus running).
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents