How to Use OR Condition in SUMPRODUCT in Google Sheets

This tutorial explains how to use OR logical conditions in the same column or across two different columns using the SUMPRODUCT formula in Google Sheets. This will help you master conditional SUMPRODUCT.

The primary purpose of SUMPRODUCT is to find the product of two or more arrays of equal size. However, you can go beyond this core purpose and use it for conditional counting or conditional summation as well. It’s not overly complex if you understand the logic behind it.

SUMPRODUCT with OR Condition in a Single Column

We will use the following material purchase data in the range A1:E to learn how to use OR conditions in the SUMPRODUCT function:

SUMPRODUCT with OR Condition in a Single Column (Sample Data)

You can use the following formula to count the number of purchases from Crusher 1:

=SUMPRODUCT(B2:B="Crusher 1")

To find the total cost of purchases from Crusher 1, use the formula:

=SUMPRODUCT(B2:B="Crusher 1", D2:D, E2:E)

This calculates the total cost by multiplying the quantities in column D with the rates in column E, only when the Loading Point is Crusher 1.

To count the number of purchases from either Crusher 1 or Crusher 2, use the OR condition in SUMPRODUCT as follows:

=SUMPRODUCT((B2:B="Crusher 1")+(B2:B="Crusher 2"))

To calculate the total purchase cost for both Crusher 1 and Crusher 2, include the Qty and Rate columns:

=SUMPRODUCT((B2:B="Crusher 1")+(B2:B="Crusher 2"), D2:D, E2:E)

That’s how you can use an OR condition in SUMPRODUCT within a single column.

SUMPRODUCT with OR Condition in Multiple Columns

In rare cases, you might need to use the OR condition in SUMPRODUCT across two different columns. Let’s consider the following data in A1:B:

SUMPRODUCT with OR Condition in Multiple Columns (Sample Data)

Suppose you want to count rows where Color 1 is “Red” or Color 2 is “White.” You can use the following formula:

=SUMPRODUCT(SIGN((A2:A="Red")+(B2:B="White")))

Explanation of the Formula

  • (A2:A="Red"): Returns TRUE for rows where Color 1 is “Red”; otherwise, it returns FALSE.
  • (B2:B="White"): Returns TRUE for rows where Color 2 is “White”; otherwise, it returns FALSE.

When you add these two conditions, the possible outcomes are:

  • 0: Neither condition is met.
  • 1: One condition is met (either “Red” in Color 1 OR “White” in Color 2).
  • 2: Both conditions are met (both “Red” in Color 1 AND “White” in Color 2).

The SIGN function ensures that any result greater than 0 (either 1 or 2) is converted to 1, allowing you to count rows where at least one condition is true.

The formula returns 3 in the example above because three rows meet at least one of the conditions.

Final Notes

Using SUMPRODUCT with OR conditions across multiple columns is not a common requirement. However, knowing this technique equips you with the flexibility to handle diverse data scenarios.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Count Consecutive Duplicates in Excel (Dynamic Array Formula)

Counting consecutive duplicates in Excel is useful for analyzing patterns, detecting repetitive sequences, and...

How to Break RANK Ties Alphabetically in Google Sheets

The RANK function in Google Sheets is commonly used to assign rankings to numerical...

Google Sheets: Highlight an Entire Column If Any Cell Has an Error

Google Sheets allows you to highlight an entire column if any cell has an...

Filter Top N per Category in Excel (Using FILTER & COUNTIFS)

You can use a combination of FILTER and COUNTIFS to filter the top N...

More like this

How to Break RANK Ties Alphabetically in Google Sheets

The RANK function in Google Sheets is commonly used to assign rankings to numerical...

Google Sheets: Highlight an Entire Column If Any Cell Has an Error

Google Sheets allows you to highlight an entire column if any cell has an...

Google Sheets: Extract Top N per Group from Query Aggregation

When working with grouped and aggregated data in Google Sheets, you might need to...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

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