Going Stellar

Home/Google Sheets reference

Google Sheets function · Array

REDUCE in Google Sheets: syntax and examples

REDUCE starts from an initial value and applies a LAMBDA to each item of the array, carrying the result forward. It returns the final accumulated value, which makes it a general tool for totals, counts and joined text.

Syntax

REDUCE(initial_value, array_or_range, LAMBDA)

Arguments

ArgumentTypeRequiredWhat it does
initial_valueanyyesThe starting value of the accumulator.
array_or_rangerangeyesThe values to walk through, one at a time.
LAMBDAfunctionyesA LAMBDA with two names, accumulator and current value. It returns the new accumulator.

Examples

The examples use this table, starting in A1:

QtyRegion
5north
8south
3east
12west
=REDUCE(0,A2:A5,LAMBDA(acc,x,acc+x))

Result: 28

A running total over four values: it equals SUM, shown step by step.

Run in a Google Sheet (English US locale) on .

=REDUCE(1,A2:A5,LAMBDA(acc,x,acc*x))

Result: 1440

Start from 1 to multiply. A start of 0 would keep the product at 0.

Run in a Google Sheet (English US locale) on .

=REDUCE(0,A2:A5,LAMBDA(acc,x,IF(x>4,acc+1,acc)))

Result: 3

Counts the values above 4 by adding 1 only when the test passes.

Run in a Google Sheet (English US locale) on .

=REDUCE("",B2:B5,LAMBDA(acc,x,IF(acc="",x,acc&", "&x)))

Result: north, south, east, west

Builds one text from many cells. The IF avoids a comma before the first item.

Run in a Google Sheet (English US locale) on .

=REDUCE(0,A2:A5,LAMBDA(acc,x,MAX(acc,x)))

Result: 12

Keeps the larger value at each step, so the end result is the maximum.

Run in a Google Sheet (English US locale) on .

Common errors

  • The LAMBDA needs exactly two names: the accumulator first, the current value second. With one name the formula returns #N/A.
  • The third argument must be a LAMBDA, not a number or a plain expression. REDUCE(0,A2:A5,5) returns #N/A.
  • The initial value sets the type. Starting from 0 and adding text gives #VALUE!, and a start of 0 in a product keeps everything at 0.
  • An empty range returns the initial value untouched, so a default such as 0 or "" doubles as the empty-case answer.

Compared with Excel

Same idea as Excel 365 REDUCE. Both use LAMBDA with the accumulator first.

Sources

  1. REDUCE (Docs Editors Help)

Markdown version · All functions