Sub topic 13
Counting and Filtering Blanks
This chapter assumes you can write a basic COUNTIFS, SUMIFS, or AVERAGEIFS formula and read criteria pairs. It also assumes you know the comparison operators from earlier chapters. It uses the sample sales data: headers in row 1, data in rows 2 to 5, and ranges that reach down 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 GiftWhy blanks need their own criteria
Real data has gaps. Notes are optional, a region is sometimes missing, and a status column stays empty until someone fills it in. You often need to ask two questions: how many rows have no value here, and what is the total for rows that do?
The *IFS functions answer both with two special criteria strings. One matches empty cells, and the other matches cells that are not empty. The details are where the wrong totals come from.
Counting empty cells
An empty-string criterion matches blank cells. This counts the sample rows with no note:
=COUNTIFS(E2:E100, "")The result is 97, not 2. The range runs to row 100, so rows 6 to 100 are blank too. The criterion has no idea where your data ends. Keep this in mind whenever you use a blank criterion on a range that is longer than the data.
The fix is to pair the blank test with a condition that only your real rows satisfy. For example, require a date:
=COUNTIFS(A2:A100, "<>", E2:E100, "")This counts rows that have a date and no note. The result is 2.
Combining a blank test with another field works the same way. This counts West rows with no note:
=COUNTIFS(B2:B100, "West", E2:E100, "")The West condition removes the unused rows, so the result is 2.
Counting non-empty cells
The criterion "<>" matches cells that are not empty. This counts rows with a note:
=COUNTIFS(E2:E100, "<>")The result is 2, for "Backorder" and "Gift".
You can use the same criterion in SUMIFS to total only the rows that have a note:
=SUMIFS(D2:D100, E2:E100, "<>")This returns 1450, which is 300 plus 1150. AVERAGEIFS accepts the same criterion:
=AVERAGEIFS(D2:D100, E2:E100, "<>")This returns 725.
The three kinds of "blank"
Excel has more than one way for a cell to look empty. The criteria treat them differently.
- A truly empty cell has nothing in it.
- A formula cell can return an empty string, for example
=IF(E2="","",E2). It looks empty but holds a formula. - A cell can contain only a space. It looks empty but holds text.
| Criterion | Truly empty | Formula returning "" | Cell with a space |
|---|---|---|---|
| `""` | Matches | Matches | Does not match |
| `"="` | Matches | Does not match | Does not match |
| `"<>"` | Does not match | Matches | Matches |
Two practical rules follow from the table.
- Use
""when you want everything that looks empty, including formula results. This is usually what you want when a helper column fills in blanks. - Use
"="when you need truly empty cells only, such as data that nobody has entered yet.
A cell holding a space is invisible to every blank test. If a blank count is lower than you expect, search the column for stray spaces. A helper column like =LEN(E2) shows which cells are not as empty as they look.
A trap with "not equal to a value"
A criterion such as "<>West" means "any cell that is not West". Blank cells are not West, so they match. This surprises people:
=COUNTIFS(B2:B100, "<>West")The result is 97, not 2. It counts East, North, and the 95 unused rows. To count only real rows with a region other than West, add a second condition on the same column:
=COUNTIFS(B2:B100, "<>West", B2:B100, "<>")The result is 2, for East and North. The same column appears in two pairs, which is allowed, as it was for date ranges.
Blank criteria driven by a cell
Earlier chapters showed criteria taken from a cell, such as G1. If G1 is empty, the function does not treat it as "match blanks". It treats the empty cell as 0, so this counts cells that contain zero:
=COUNTIFS(E2:E100, G1)Write the equals sign into the criterion instead:
=COUNTIFS(E2:E100, "="&G1)When G1 is empty, the criterion becomes "=", which matches truly empty cells. When G1 holds "Gift", it becomes "=Gift", which matches that text. One formula then handles both cases.
Blanks in the range being added or averaged
The sum range and average range can contain blanks too. SUMIFS treats empty cells as nothing to add. AVERAGEIFS skips empty cells in its average range, so a missing amount does not pull the mean toward zero. This is usually what you want. It does mean that a row with a missing amount still matches the criteria but contributes no value.
To find these rows, count them directly:
=COUNTIFS(B2:B100, "West", D2:D100, "")If this returns more than 0, some West rows have no amount. The West total and average are then based on fewer rows than the West row count suggests. Comparing the two counts is a quick data-quality check:
=COUNTIFS(B2:B100, "West") - COUNTIFS(B2:B100, "West", D2:D100, "")This gives the number of West rows that actually have an amount.
Common mistakes
- Expecting
""to find cells with a space. It does not. - Using
"<>"to count "cells with real content" when formulas return"". Those formula cells still count as non-empty. - Forgetting that
"<>West"includes blank cells. - Pointing a criterion at an empty cell and getting a count of zeros instead of a count of blanks.
- Counting blanks over a whole column or an oversized range without a second condition.
Exercise
A helper column F holds the formula =IF(E2="","",E2) in rows 2 to 100. You want the number of rows from 2 to 100 where F has no visible content, and you want formula results that return an empty string to count. Which criterion do you use, and what happens if you use "=" instead?
Show answer
Use COUNTIFS(F2:F100, ""). The empty-string criterion matches both truly empty cells and formulas that return an empty string. The "=" criterion matches only truly empty cells, so it would return 0 here, because every cell in F contains a formula.
Exercise
Write a formula that counts rows in B2:B100 where the region is not West and not blank. Using the sample data, what does it return?
Show answer
=COUNTIFS(B2:B100, "<>West", B2:B100, "<>"). It returns 2, for the East and North rows. The "<>" pair excludes the 95 unused rows that "<>West" would otherwise match.