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 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.

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

More like this

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

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.