To count cells in Google Sheets that meet multiple criteria, use COUNTIFS (plural) for AND logic across different columns or rows, or combine multiple COUNTIF functions with a plus sign (+) for OR logic. For example, =COUNTIFS(A2:A10,"Red",B2:B10,">10") counts rows where column A is “Red” AND column B is greater than 10.
Why COUNTIF Alone Isn’t Enough
The single COUNTIF function accepts only one range and one criterion. It’s perfect for simple questions like “how many cells in A2:A10 say ‘Yes’?” But when you need to filter by two or more conditions—say, count sales in the West region that exceeded $500—a single COUNTIF can’t do it. You’d either need to add a helper column that combines the conditions, or switch to COUNTIFS, which was designed exactly for this.
Google Sheets introduced COUNTIFS to handle multiple criteria with AND logic. It evaluates each range/criterion pair, and a row is counted only if every pair is true. This is the most common and recommended approach for multi-condition counting.
Using COUNTIFS for AND Logic (All Conditions Must Match)
The syntax is:
=COUNTIFS(criteria_range1, criterion1, [criteria_range2, criterion2, ...])
You can add up to 127 range/criterion pairs. Each range must have the same number of rows and columns, otherwise you’ll get a #VALUE! error.
Example: Assume you have a product list with names in A2:A20 and quantities in B2:B20. To count how many products have a name starting with “A” AND a quantity greater than 5:
=COUNTIFS(A2:A20,"A*",B2:B20,">5")
If the data has two rows matching (e.g., “Apple” with 7 and “Apricot” with 9), the formula returns 2.
Important details:
- Text criteria must be in double quotes:
"Yes"or"A*". - Numeric comparisons also need quotes:
">10","<=","&"&50(if you reference a cell, concatenate with &). - Wildcards work:
*(any sequence),?(single character), and~to escape them. - Case-insensitive: "red" and "RED" are treated the same.
Using Multiple COUNTIF with + for OR Logic (Any Condition Matches)
When you want to count cells that meet at least one of several criteria, you can't use COUNTIFS because it requires all conditions to be true. Instead, add multiple COUNTIF functions together:
=COUNTIF(A2:A10,"Red") + COUNTIF(A2:A10,"Blue")
This counts every cell that is either "Red" or "Blue". Be careful not to double-count cells that meet both criteria—but since a single cell can only have one value, that's not an issue here. If your criteria are in different columns and you want OR logic, you'd need a different approach, such as using SUMPRODUCT or a helper column.
Example: Count orders in column A that are either "Pending" or "Shipped":
=COUNTIF(A2:A100,"Pending") + COUNTIF(A2:A100,"Shipped")
Using SUMPRODUCT for Complex OR/AND Combinations
For more flexible logic—like counting rows where (A="X" AND B>10) OR (A="Y" AND B<5)—you can use SUMPRODUCT with array expressions. This is a powerful alternative that doesn’t require helper columns.
Syntax:
=SUMPRODUCT((range1=criteria1)*(range2>criteria2))
Each condition returns TRUE/FALSE, and multiplying them converts to 1/0. SUMPRODUCT adds the results.
Example: Count rows where column A is “Red” AND column B is greater than 10, OR column A is “Blue” AND column B is less than 5:
=SUMPRODUCT(((A2:A20="Red")*(B2:B20>10)) + ((A2:A20="Blue")*(B2:B20<5)))
This formula works because the plus sign acts as OR between the two parenthesized groups. The multiplication inside each group acts as AND.
One caveat: SUMPRODUCT can be slower on very large datasets (tens of thousands of rows), but for typical spreadsheets it’s fine.
Common Mistakes and How to Fix Them
- Mismatched range sizes: All ranges in COUNTIFS must have the same dimensions. If you use A2:A20 and B2:B21, you’ll get an error. Fix by aligning the ranges.
- Forgetting quotes around criteria: Text and comparison operators need double quotes.
=COUNTIFS(A2:A20,Red)will treat Red as a named range and fail. Use"Red". - Using COUNTIFS for OR logic: It won’t work as expected; it will return 0 because no row meets both conditions. Switch to multiple COUNTIF or SUMPRODUCT.
- Blank cells: COUNTIFS ignores blank cells unless you specifically use
""as a criterion. To count blanks, use=COUNTIF(A2:A20,""). - Date criteria: Dates must be entered as dates or with DATE() function, e.g.,
">"&DATE(2025,1,1).
COUNTIF vs. COUNTIFS vs. SUMPRODUCT: Which to Choose?
Here’s a quick decision guide:
- Single condition: Use COUNTIF.
- Multiple conditions, all must be true (AND): Use COUNTIFS.
- Multiple conditions, any can be true (OR) on the same column: Use multiple COUNTIF with +.
- Complex OR/AND across different columns: Use SUMPRODUCT.
- Need to count unique values with criteria: Combine with UNIQUE or use QUERY (e.g.,
=COUNTA(UNIQUE(FILTER(A2:A20,B2:B20="Yes")))).
For most real-world tasks, COUNTIFS is the go-to because it’s readable and efficient. SUMPRODUCT is more flexible but can be harder to read.
Frequently Asked Questions
Can I use COUNTIFS with wildcards like * and ?
Yes. Use * for any sequence of characters and ? for a single character. For example, =COUNTIFS(A2:A20,"A*",B2:B20,">5") counts rows where column A starts with “A” and column B is greater than 5. To match a literal asterisk, use ~*.
How do I count cells that contain specific text in multiple columns?
Suppose you want to count rows where column A contains “apple” OR column B contains “apple”. You can’t use COUNTIFS because it’s OR. Use: =COUNTIF(A2:A20,"*apple*") + COUNTIF(B2:B20,"*apple*"), but note this double-counts rows where both columns contain “apple”. To avoid double-counting, use SUMPRODUCT with OR logic: =SUMPRODUCT((ISNUMBER(SEARCH("apple",A2:A20)) + ISNUMBER(SEARCH("apple",B2:B20)) > 0)*1).
Why is my COUNTIFS returning 0 even though I see matching rows?
Most likely a mismatch in data types. For example, numbers stored as text won’t match numeric criteria. Check if the cells are left-aligned (text) or right-aligned (numbers). Use the VALUE function to convert text to numbers, or use "*"&number as a text criterion. Also check for extra spaces—use TRIM to clean data.
Can I count based on cell color in Google Sheets?
No, there is no built-in function to count by background color. You’d need to use Google Apps Script to write a custom function, or use a filter view and count manually. This is a common limitation.
Does COUNTIFS work with entire columns like A:A?
Yes, but using entire columns (e.g., A:A) can slow down calculations because it processes 1,048,576 rows. It’s better to limit to your actual data range, like A2:A1000.
How do I count multiple criteria in different sheets?
You can reference ranges from other sheets in COUNTIFS. For example, =COUNTIFS(Sheet2!A2:A20,"Yes",Sheet2!B2:B20,">10"). Just include the sheet name with an exclamation mark.
Related
- How to Update a Dictionary in Appian (AEP)
- How to Add in Excel: Sum, AutoSum & More
- Hot Air Balloon Numbers: What They Mean & Why They Matter
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Data Validate in Excel with Drop-Down ListsTo data validate in Excel for Microsoft 365 on Windows, select the cells you want to control, go…
- How to Combine Columns in Excel Without Losing DataTo combine two columns in Excel without removing their original contents, put the result in a new, empty…
- How to Insert an Image Into a Cell in Excel ProperlyIn Excel for Microsoft 365 on Windows, select a cell, then choose Insert > Pictures > Place in…
- Speed Camera Detection Speed: How Fast They WorkSpeed cameras can detect your speed in as little as 0.1 seconds, with most modern radar- and laser-based…
- Is Excel Free? Microsoft 365 Plans and Free OptionsYes—Microsoft Excel is free to use in a web browser with a Microsoft account, and basic use of…
- Google Sheets: Format a Cell as a DateTo format a cell as a date in Google Sheets, select the cell or range, then choose Format…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.