Note: The other languages of the website are Google-translated. Back to English
English English

Count number of rows with multiple OR criteria

To count the number of rows with multiple criteria in different columns, with OR logic, the SUMPRODUCT function can help you. For example, I have a product report as below screenshot shown, now, I want to count the rows where the product is “T-shirt” or the color is “Black”. How to deal with this task in Excel?


Count number of rows with multiple OR criteria

In Excel, using the SUMPRODUCT function to count the number of rows with multiple criteria in different columns, the generic syntax is:

=SUMPRODUCT(--((criteria1)+(criteria2)>0))
  • criteria1, criteria2: The logical expressions used to meet the conditions.

For instance, to count the number of rows where the product is “T-shirt” or the color is “Black”, please enter or copy the following formula into a blank cell to output the calculation, and press Enter key to get the result:

=SUMPRODUCT(--((A2:A12="T-shirt")+(C2:C12="Black")>0))


Explanation of the formula:

=SUMPRODUCT(--((A2:A12="T-shirt")+(C2:C12="Black")>0))

  • (A2:A12="T-shirt")+(C2:C12="Black"):
    The first logical expression checks if the product is “T-shirt”, it returns the result as this: {FALSE;TRUE;TRUE;FALSE;TRUE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE}.
    The second logical expression checks if the color is “Black”, and returns the result like this: {TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;FALSE;FALSE;TRUE}.
    The OR logic requires addition, so, the two logical expressions are joined by an addition sign (+). The math operation automatically converts the TRUE and FALSE values to 1s and 0s, so, you will get an array like this: {1;1;1;0;1;0;1;1;0;0;2}.
  • --((A2:A12="T-shirt")+(C2:C12="Black")>0)=--({1;1;1;0;1;0;1;1;0;0;2}>0): First, check for the values in the array greater than 0: If a value is greater than 0, a TRUE is displayed; if less than 0, a FALSE is displayed. And then the double negative sign forces the TRUEs and FALSEs to be 1s and 0s, so you will get this: {1;1;1;0;1;0;1;1;0;0;1}.
  • SUMPRODUCT(--((A2:A12="T-shirt")+(C2:C12="Black")>0))=SUMPRODUCT({1;1;1;0;1;0;1;1;0;0;1}): At last, the SUMPRODUCT function sums all the values in the array to get the result: 7.

Tips:

To add more conditions, you just need to add the logical expressions inside the SUMPRODUCT function, such as, to count number of rows where the product is “T-shirt”, or the color is “Black”, or Qty is “50”, please apply the below formula:

=SUMPRODUCT(--((A2:A12="T-shirt")+(C2:C12="Black")+(D2:D12=50)>0))


Relative function used:

  • SUMPRODUCT:
  • The SUMPRODUCT function can be used to multiply two or more columns or arrays together, and then get the sum of products.

More articles:

  • Count Number Of Rows That Contain Specific Values
  • It may be easy for us to count the number of cells with specific value in an Excel worksheet. However, to get the number of rows that contain specific values could be rather complicated. In this case, a more complex formula based on the SUM, MMULT, TRANSPOSE and COLUMN functions may do you a favor. This tutorial will talk about how to create this formula to deal with this job in excel.
  • Count Rows If Meet Internal Criteria
  • Supposing, you have a report of product sales of this year and last year, and now, you may need to count products where the sales in this year are greater than last year, or the sales in this year are less than last year as below screenshot shown. Normally, you can add a helper column for calculating the sale difference between the two years, and then use COUNTIF to get result. But, this article, I will introduce the SUMPRODUCT function to get the result directly without any helper column.
  • Count Rows If Meet Multiple Criteria
  • Count the number of rows in a range based on multiple criteria, some of which depends on the logical tests that work at the row-level, the SUMPRODUCT function in Excel may do you a favor.

The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300 powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) and save 80% time for you.

  • Designed for 1500 work scenarios, helps you solve 80% Excel problems.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
  • Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
  • 30-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years.
Ribbon of Excel (with Kutools for Excel installed)

Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

  • One second to switch between dozens of open documents!
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Firefox, And New Internet Explorer.
Screen Shot of Excel (with Office Tab installed)
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations