How to Use the REDUCE Function in Google Sheets

Published on

The REDUCE function in Google Sheets processes an array into a single accumulated result by repeatedly applying the same LAMBDA function to each element.

Many of you might have come across REDUCE in complex formulas—whether it’s merging data from multiple tabs or sheets, filtering, stacking arrays, and so on. In such cases, REDUCE doesn’t just return a single value. Instead, it returns an array by stacking the accumulated value at each iteration, either vertically or horizontally.

Understanding this behavior is just as important.

REDUCE Function Syntax and Arguments in Google Sheets

REDUCE syntax:

REDUCE(initial_value, array_or_range, LAMBDA)

Where:

  • initial_value – Sets the initial or starting value of the accumulator.
  • array_or_range – The array or range to be reduced.
  • LAMBDA – A custom LAMBDA function applied to each element of the array_or_range. It takes two arguments.

LAMBDA syntax:

LAMBDA(name1, name2, formula_expression)

Here, name1 is the accumulator, and name2 represents the current element from the array. The formula expression performs the desired operation using these two.

To better understand the syntax of the REDUCE function in Google Sheets, try the example below.

How to Use the REDUCE Function in Google Sheets

Let’s try the following formula in an empty cell:

=REDUCE(0, {5; 4; 9; 10}, LAMBDA(a, v, a + v))

This returns 28.

Here’s what’s happening:

  • The initial value in the accumulator is 0.
  • The array to reduce is {5; 4; 9; 10}.
  • We’ve defined two names: a for the accumulator and v for the current array element.
  • The formula expression is a + v, which means that in each iteration, the current element is added to the accumulator.

So, it works like:
(((0 + 5) + 4) + 9) + 10 = 28

The SCAN Connection

Now look at the SCAN function with a similar structure (just replace REDUCE with SCAN):

=SCAN(0, {5; 4; 9; 10}, LAMBDA(a, v, a + v))
Comparison of SCAN and REDUCE functions in Google Sheets showing how SCAN returns intermediate values while REDUCE returns only the final result

SCAN and REDUCE Functions – Similarities

While REDUCE returns only the final accumulated value, SCAN returns all intermediate values from each iteration.

Stacking in REDUCE

Now replace a + v in the REDUCE formula with VSTACK(a, CHOOSEROWS(a, -1) + v), like this:

=REDUCE(0, {5; 4; 9; 10}, LAMBDA(a, v, VSTACK(a, CHOOSEROWS(a, -1) + v)))

Here, we start with an initial value of {0} and use VSTACK to keep adding each new sum to the growing array. CHOOSEROWS(a, -1) fetches the last value in the accumulator, and v is the current element in the array.

The result is a stacked (vertical) list of cumulative sums — similar to what the SCAN function returns — but it includes the initial value 0.

0
5
9
18
28

This is just a simple example to help you understand the concept. This technique is used in various advanced scenarios.

Examples of Using the REDUCE Function in Google Sheets

Below are four practical examples of using the REDUCE function in Google Sheets. Most of them can be replaced with regular formulas. But the purpose of these examples is to help you get familiar with how REDUCE works.

In all these examples, the initial value of the accumulator is 0.
If you set it to 100, the outputs in the cyan-highlighted cells would be 102, 165, 202, and 103 respectively.

Examples of the REDUCE function in Google Sheets demonstrating conditional count and sum use cases

1. REDUCE Function for Conditional Sum

The formulas in cells D4 and D6 show how to use the REDUCE function for conditional summing.

Formula in D4 – Sum if Value Is Greater Than 30

=REDUCE(0, B2:B, LAMBDA(a, v, IF(v > 30, a + v, a)))

Equivalent to:

=SUMIF(B2:B, ">30")

This adds only values greater than 30 to the accumulator.

Formula in D6 – Sum of Odd Numbers

=REDUCE(0, B2:B, LAMBDA(a, v, IF(ISODD(v), a + v, a)))

SUMIF alternative:

=ARRAYFORMULA(SUMIF(ISODD(B2:B), TRUE, B2:B))

These are great examples of using the REDUCE function in Google Sheets for condition-based summing.

2. REDUCE Function for Conditional Count

The formulas in D2 and D8 act as conditional counts.

Assume the values in B2:B represent the age of participants in a competition.

Formula in D2 – Count if Age Is Greater Than 30

=REDUCE(0, B2:B, LAMBDA(a, v, a + (v > 30)))

Equivalent COUNTIF:

=COUNTIF(B2:B, ">30")

Formula in D8 – Count if Age Is Between 20 and 30

=REDUCE(0, B2:B, LAMBDA(a, v, a + (AND(v > 20, v < 30))))

Equivalent COUNTIFS:

=COUNTIFS(B2:B, ">20", B2:B, "<30")

Other Miscellaneous Use Cases

Looking at the above examples, you might think the REDUCE function is mainly for conditional sums and counts.

But that’s not the case!

The REDUCE function in Google Sheets can do a lot more.

Example – Get the Last Numeric Value in Column B

=REDUCE(0, B:B, LAMBDA(a, v, IF(v = "", v + a, v)))

To get the last numeric value in row 2, replace B:B with 2:2.

If the values are mixed (text + numbers), replace the initial value 0 with "", and use v & a instead of v + a.

Example – Conditional Total Using OFFSET

=REDUCE(0, A:A, LAMBDA(a, v, IF(v = "apple", OFFSET(v, 0, 1) + a, a)))

This totals values in column B where the corresponding value in column A is “apple”.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

Reservation and Booking Status Calendar Template in Google Sheets

My reservation and booking status calendar template in Google Sheets uses spreadsheet cells as rooms and highlighting to show availability/non-availability. I have used a few...
Multi Row Dynamic Dependent Drop-Down List in Google Sheets

Multi-Row Dynamic Dependent Drop-Down List in Google Sheets

We can create a multi-row dynamic dependent drop-down list in Google Sheets without using Google Apps Script. This tutorial explains how. I will only use...

Date-Related Conditional Formatting Rules in Google Sheets

Based on my experience, much of the conditional formatting in Google Sheets centers around dates. Therefore, in this tutorial, I've included several date-related conditional...
Populate info in Spreadsheet

Auto-Populate Information Based on Drop-down Selection in Google Sheets

Another awesome Google Sheets tutorial! This time, we'll learn how to auto-populate information based on a drop-down selection. Spreadsheet applications are always enticing to me....
USAGE OF DATE IN QUERY SYNTAX

How to Use Date Criteria in Query Function in Google Sheets [Date in Where...

Using dates as the criteria are a complicated part of any criteria formation in the Google Sheet functions. In most cases, you can not...

More like this

Rental Property Manager Template for Google Sheets (Free & Fully Automated)

Do you want to manage all aspects of your rental properties, such as tracking...

Content Calendar Template in Google Sheets (Free, Dynamic & Fully Automated)

Are you a content creator managing posts across multiple platforms — Blogs, YouTube, Twitter...

Funnel Chart in Google Sheets (Dynamic without Helper Columns)

Most tutorials online create a funnel chart in Google Sheets using a stacked bar...

LEAVE A REPLY

This site uses Akismet to reduce spam. Learn how your comment data is processed.