Sub topic 4
COUNTIFS: counting rows that meet conditions
This chapter assumes you can enter and copy formulas and that you know relative and absolute references. It also assumes you have used COUNT. It covers how COUNTIFS evaluates rows, how criteria behave for counting, and the errors you are most likely to meet.
What COUNTIFS does
COUNTIFS counts the rows where every condition you give is true. Unlike SUMIFS and AVERAGEIFS, it has no range of values to add or average. Every argument is part of a pair: a range, then the criteria to test against that range.
=COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], ...)The examples use the sales layout from earlier in the tutorial. Headers are in row 1, and data runs from row 2 to row 100.
A: Date B: Region C: Product D: Amount E: Notes
2025-01-05 West Laptop 1200
2025-01-09 East Monitor 300 Backorder
2025-02-02 West Monitor 310
2025-02-14 North Laptop 1150 GiftThis formula counts West rows where the product is Laptop:
=COUNTIFS(B2:B100, "West", C2:C100, "Laptop")With the four rows shown, the result is 1. Only the first row passes both tests.
How a row is evaluated
Excel walks down the ranges together. For row 2, it checks B2 against the first criterion and C2 against the second. The row counts only if every pair passes. This is AND logic.
Two consequences follow:
- COUNTIFS counts rows, not values. A row that matches counts once, however many pairs it satisfies.
- The ranges can be in different columns, but they must be the same size and shape, so that row 5 in one range lines up with row 5 in the others.
One condition is allowed
COUNTIFS works with a single pair, so it can replace COUNTIF everywhere. Many people use COUNTIFS for all conditional counts. Then adding a second condition later only means adding two arguments.
=COUNTIFS(B2:B100, "West")Writing criteria for counting
The criteria rules are the same ones SUMIFS uses, but a few matter more when you count.
Exact matches and operators
A bare value means "equals". Text matching ignores letter case, so "west" and "West" both match. To use a comparison, put the operator inside the quoted string.
=COUNTIFS(D2:D100, ">=1000")With the sample rows, this counts 1200 and 1150, so the result is 2.
To take the threshold from a cell, join the operator and the cell with &:
=COUNTIFS(B2:B100, "West", D2:D100, ">=" & G1)Date ranges
Use the same date column in two pairs to set both ends. Make the end date exclusive so no day is missed.
=COUNTIFS(A2:A100, ">=" & DATE(2025,1,1), A2:A100, "<" & DATE(2025,2,1))With the sample data, this returns 2 (5 January and 9 January). The dates in column A must be real Excel dates. Text that only looks like a date will not match.
Wildcards
* matches any run of characters, including none. ? matches exactly one character.
=COUNTIFS(C2:C100, "Lap*")To match a literal * or ?, put ~ before it, as in "~*".
Blanks and non-blanks
An empty-string criterion matches empty cells. "<>" matches cells that are not empty.
=COUNTIFS(B2:B100, "West", E2:E100, "")This counts West rows with no note. It returns 2 on the sample data.
Watch what happens when the blank test is the only condition:
=COUNTIFS(E2:E100, "")This counts every empty cell in E2:E100, including the unused rows 6 to 100. On the sample data it returns 96, not 2. Pair the blank test with a condition that only filled rows satisfy, such as a non-blank Date.
=COUNTIFS(A2:A100, "<>", E2:E100, "")Numbers stored as text
A criterion of "5" or 5 matches both the number 5 and the text "5". So COUNTIFS can count values that SUMIFS then ignores, because SUMIFS cannot add text. If your count and your total disagree, check whether the sum range contains numbers stored as text. The check is =COUNT(D2:D100) against =COUNTA(D2:D100). If the two results differ, some cells are text or something else that is not a number.
OR logic for counts
Pairs are combined with AND, so you cannot list two values for one field in one pair. Add two COUNTIFS results instead, or use an array constant:
=COUNTIFS(B2:B100, "West") + COUNTIFS(B2:B100, "East")=SUM(COUNTIFS(B2:B100, {"West","East"}))Both return 3 on the sample data. This works only when the values are mutually exclusive. If a row could match both, it would be counted twice. A Region cell holds one value, so there is no overlap here.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `#VALUE!` | Ranges have different sizes, such as `B2:B100` with `C2:C99` | Make every range the same number of rows and columns |
| `#VALUE!` | A criterion string is longer than 255 characters | Shorten it, or split the test into several pairs |
| `#VALUE!` | A range points to a closed workbook | Open the source workbook, or bring the data into this one |
| Result is 0 but rows should match | Extra spaces in the data, such as `"West "` | Clean the data with TRIM, or use a wildcard like `"West*"` |
| Result is 0 on a numeric condition | Operator written outside quotes, such as `>=1000` | Write it as the string `">=1000"` |
| Count too high on a blank test | Unused rows count as blank | Add a pair that only filled rows satisfy |
| Count too low on a date test | Dates are stored as text | Convert them to real dates |
Unlike AVERAGEIFS, COUNTIFS does not raise #DIV/0! when nothing matches. It returns 0, so no IFERROR wrapper is needed.
Using COUNTIFS in a summary grid
Locked data ranges and mixed references on the criteria cells let one formula fill a region-by-product table. Put regions down column G, starting at G2, and products across row 1, starting at H1.
=COUNTIFS($B$2:$B$100, $G2, $C$2:$C$100, H$1)$G2 keeps the column fixed while the row moves as you copy down. H$1 keeps the row fixed while the column moves as you copy across. If your data is an Excel table named Sales, structured references grow with the data:
=COUNTIFS(Sales[Region], "West", Sales[Product], "Laptop")Exercise
Using the sample sales layout, which formula counts the rows for the West region that have a Notes entry and an Amount above 1000? Say what it returns for the four rows shown.
Show answer
=COUNTIFS(B2:B100, "West", E2:E100, "<>", D2:D100, ">1000"). The West rows are 2025-01-05 (no note) and 2025-02-02 (no note, and an Amount of 310). Neither has a note, so the formula returns 0.
Exercise
A colleague writes =COUNTIFS(C2:C100, "Laptop", D2:D99, ">1000") and gets #VALUE!. What is wrong, and what is the fix?
Show answer
The first range has 99 rows (C2:C100) and the second has 98 (D2:D99). COUNTIFS requires equal sizes. Change the second range to D2:D100.