Sub topic 2
COUNTIFS: counting rows that meet a condition
This chapter covers COUNTIFS with a single condition. You will see how its arguments work, how it matches text and numbers, and which errors show up most often. I assume you can enter formulas in Google Sheets, read range notation such as A2:A100, and use COUNT. Later chapters add more conditions, operators, wildcards, and dates.
What COUNTIFS does
COUNTIFS counts the rows in a range that meet a condition. COUNT counts every numeric cell in a range. COUNTIFS first tests each cell against a criterion, then counts only the cells that pass.
The sample data used in this tutorial is a sales table in A1:E100. Row 1 holds headers. Rows 2 to 100 hold the data.
| Column | Header | Example value |
|---|---|---|
| A | Region | West |
| B | Product | Widget |
| C | Date | 2026-01-14 |
| D | Units | 12 |
| E | Revenue | 480 |
Syntax
=COUNTIFS(criteria_range1, criterion1, [criteria_range2, criterion2, ...])Each condition is a pair: a range to look at, then the test to apply to it. This chapter uses one pair. The brackets show that more pairs are optional, and a later chapter covers them.
The main example counts the rows whose Region is "West":
=COUNTIFS(A2:A100, "West")Sheets checks each cell in A2:A100, and every cell equal to "West" adds 1 to the count. The result is a single number.
How matching works
The criterion decides which cells count. Several rules apply even to the simplest form.
Text matching ignores case
"West", "west", and "WEST" all match the same cells. A criterion given as plain text means "equal to this text", and the whole cell must match. The criterion "West" does not match "Northwest" or "West Coast". Partial matches need wildcards, which a later chapter covers.
Numbers and text that looks like numbers
A numeric criterion matches numeric cells with that value:
=COUNTIFS(D2:D100, 12)This counts the rows where Units is exactly 12. The criterion "12" in quotes gives the same result, because Sheets reads it as a test for the number 12. Both forms also match a cell holding the text "12". This is why a column of numbers stored as text can still seem to work with COUNTIFS while behaving badly in other functions.
Matching against a cell
The criterion can be a cell reference instead of typed text. If G2 contains "West", then these two formulas give the same result:
=COUNTIFS(A2:A100, "West")
=COUNTIFS(A2:A100, G2)The second form lets you change the region by editing one cell. This is the basis of the summary table built near the end of the tutorial.
Why the range is a criteria range
The first argument is the range that is tested. It is not a range of values to add up. In COUNTIFS the tested range and the counted rows are the same thing, because the function only counts. SUMIFS and AVERAGEIFS separate the two: they take an extra range holding the values to add or average, and that range comes first. Keep this difference in mind. The next two chapters cover those functions.
What gets counted
COUNTIFS returns the number of rows that pass, not the number of cells with values. Three consequences follow.
- A matching cell is counted even if other columns in that row are empty.
- Each row is counted at most once per call, because with a single pair each cell is tested once.
- If nothing matches, the result is 0. COUNTIFS never returns an error for zero matches. This differs from AVERAGEIFS, which returns #DIV/0! in that case.
Worked example
Suppose the table contains these rows:
| Row | A (Region) | B (Product) | D (Units) |
|---|---|---|---|
| 2 | West | Widget | 12 |
| 3 | East | Gadget | 5 |
| 4 | west | Widget | 8 |
| 5 | Northwest | Gizmo | 20 |
| 6 | West | Gadget | 12 |
Applying =COUNTIFS(A2:A6, "West") gives 3. Rows 2, 4, and 6 match. Row 4 matches despite its lowercase "west". Row 5 does not match, because "Northwest" is not equal to "West".
Applying =COUNTIFS(D2:D6, 12) gives 2, from rows 2 and 6.
Absolute and relative references
When you fill a formula down or across, relative references shift. Suppose a list of regions sits in G2:G5 and you want a count beside each one. This formula, in H2, does not work as intended when filled down:
=COUNTIFS(A2:A100, G2)In H3 it becomes =COUNTIFS(A3:A101, G3), so the range moves down one row and the count is wrong. Anchor the range with dollar signs:
=COUNTIFS($A$2:$A$100, G2)Now the range stays fixed while G2 changes to G3, G4, and G5 as you fill down. The criterion cell stays relative on purpose, so each row looks up its own region.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Result is 0 but you expect matches | Trailing or leading spaces in the data, such as "West " | Clean the data with TRIM, or correct the cells |
| Result is 0 for a numeric test | The criterion text has a typo or the values are in a different format | Check the cell contents, not just how they display |
| Count is too high by 1 | The header row is inside the range | Start the range at row 2 |
| Counts change when filled down | The range is not anchored | Use $A$2:$A$100 |
| #ERROR! or a parse error | A text criterion is missing its quotes | Write "West", not West |
Trailing spaces are the most common cause of a surprising 0. The cell looks like "West" but contains "West ", so it does not equal the criterion. You can test a cell with =LEN(A2). If the result is 5 instead of 4, a hidden space is present.
Checking your result
A quick check is to compare COUNTIFS against a visible filter. Apply a filter on the Region column, choose "West", and look at the row count Sheets shows. It should equal the formula's result. If it does not, look for spacing, case-insensitive duplicates you did not expect, or a range that stops short of your data.
Exercise
A2:A100 holds regions, and G2 contains the text "East". Write a formula that counts the rows whose Region equals the value in G2. Then say what changes if you fill the formula down to G3 without any dollar signs, and how to prevent it.
Show answer
Use =COUNTIFS(A2:A100, G2). Filled down without anchors, the range shifts to A3:A101 in the next row, so the count covers the wrong rows. Anchor the range with =COUNTIFS($A$2:$A$100, G2). G2 stays relative, so each row uses its own criterion cell.
Exercise
A table has the regions "West", "west ", "WEST", and "Northwest" in four different rows of A2:A5. How many rows does =COUNTIFS(A2:A5, "West") count, and why?
Show answer
It counts 2. "West" and "WEST" match, because text matching ignores case. "west " has a trailing space, so it does not equal "West". "Northwest" is not equal to "West", because a plain text criterion must match the whole cell.