Skip to main content

Count number of rows with multiple OR criteria

Author: Xiaoyang Last Modified: 2021-09-22

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

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates  |  Delete Blank Rows  |  Combine Columns or Cells without Losing Data  |  Round without Formula ...
Super VLookup: Multiple Criteria  |  Multiple Value  |  Across Multi-Sheets  |  Fuzzy Lookup...
Adv. Drop-down List: Easy Drop Down List  |  Dependent Drop Down List  |  Multi-select Drop Down List...
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus  |  Design View  |  Big Formula Bar  |  Workbook & Sheet Manager | Resource Library (Auto Text)  |  Date Picker  |  Combine Worksheets  |  Encrypt/Decrypt Cells  |  Send Emails by List  |  Super Filter  |  Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters ...)  |  50+ Chart Types (Gantt Chart ...)  |  40+ Practical Formulas (Calculate age based on birthday ...)  |  19 Insertion Tools (Insert QR Code, Insert Picture from Path ...)  |  12 Conversion Tools (Numbers to Words, Currency Conversion ...)  |  7 Merge & Split Tools (Advanced Combine Rows, Split Excel Cells ...)  |  ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...

Description


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, Edge and Firefox.
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