Excel’s COUNTIF function excludes zeros by default, which can be frustrating if you need to count all numeric entries, including empty cells or zeros. The solution is simple: use a custom formula with `COUNTIF` + `IF` or `LEN` to force counting zeros as valid values. This ensures zeros are counted alongside actual numbers, making your data analysis accurate for budgeting, inventory checks, or any scenario where zeros represent "no data" or "none." No extra add-ins required—just basic formulas.
What You’ll Need
- An Excel spreadsheet with numeric data (including zeros or empty cells).
- The COUNTIF function in Excel (available in Office 2016+ and modern versions).
- Basic knowledge of Excel formulas (or willingness to test them).
- A computer running Excel (Windows/macOS or Microsoft 365).
Step-by-Step
- Identify the range to count.
Determine the cells you want to count (e.g., `A2:A100`). Note that Excel counts empty cells as zero unless you use a custom formula. If your data includes empty rows/columns, adjust the range accordingly.
- Use the standard COUNTIF (if zeros should be ignored).
If zeros are irrelevant, use the basic formula:
=COUNTIF(range, ">=0")This counts all values ≥0, skipping negative numbers if they exist. Works but misses zeros in "no data" contexts. - Count zeros explicitly with
COUNTIFS.To force counting zeros (e.g., in a budgeting list where 0 = no purchase), use:
=COUNTIFS(range, "<>0", range, "<>0")This fails—so instead, use this trick: - Include zeros with a helper formula.
Wrap the logic in a formula like this:
=COUNTIF(A2:A100, ">0") + COUNTIF(A2:A100, "=0")Breakdown:
COUNTIF(A2:A100, ">0")counts positive numbers.COUNTIF(A2:A100, "=0")counts zeros.- Add them together to total all numeric entries.
- Use this one-line solution (recommended).
Replace empty cells with a placeholder (e.g., 0) using:
=SUMPRODUCT(--(A2:A100="0"), TRUE) + COUNTIF(A2:A100, ">0")This is overkill for most cases, so prefer the two-step method above. - Test with a sample range.
Enter a small test range (e.g., `{1, 0, -2, 0, 3}`). Verify:
=COUNTIF(A2:A5, ">0") + COUNTIF(A2:A5, "=0")returns 4 (1 + 0 + 2 + 3). Adjust ranges if needed.
Common Mistakes
- Forgetting to include zeros.
If your data has zeros but your formula only counts ">0", empty cells or -1 values will be missed. Always test with a mix of numbers, zeros, and negatives.
- Range errors.
Typing `A2:A100` but forgetting to include `A101` can truncate results. Use the
INDEXorOFFSETfunctions to dynamically adjust ranges if needed. - Overcomplicating with helper functions.
Formulas like
SUMPRODUCTadd complexity without benefit. Prefer simple addition ofCOUNTIFcalls. - Ignoring empty cells.
Excel’s
COUNTIFtreats empty cells as zero by default. If you need to exclude them, add"<>"to the criteria (e.g.,COUNTIF(A2:A100, "<>")), but this excludes zeros too.
Tips
- Use the iserror function for unknown values.
If your data has non-numeric values (e.g., text), wrap them in
IFERROR:=COUNTIFS(A2:A100, "!<>"&TEXT(A2, "General"), A2:A100, "<>0")This counts only numeric values ≥0. - Leverage helper columns.
Create a temporary column with zeros, then use
COUNTIFon that. Example:Column B: =IF(A2="0", "0", "") Count zeros: =COUNTIF(B2:B100, "0")
Useful for large datasets with inconsistent formatting. - Check for text-as-numbers.
If cells contain "0", "zero", or other text, use:
=COUNTIF(TEXTJOIN(",", TRUE, A2:A100), ">0") + COUNTIF(TEXTJOIN(",", TRUE, A2:A100), "=0")This forces Excel to treat text as numbers. - Avoid
COUNTAfor zeros.COUNTAcounts all non-empty cells, including text or blanks. To count only zeros, useCOUNTIFwith "<>"":=COUNTIF(A2:A100, "<>""")But this excludes all empty cells—so useCOUNTIF+COUNTBLANKSfor empty-cell-free counting.
Troubleshooting
- Formula returns zero when it shouldn’t.
Double-check your range (e.g., press
F2+Ctrl+.to confirm selected cells). Ensure no extra spaces or hidden characters are skewing results. - Error: "#VALUE!" or "#DIV/0!"
If using
COUNTIFS, verify all criteria match the range. For example:=COUNTIFS(A2:A100, ">0")will fail if A2:A100 contains text. UseIFERRORor validate data first. - Results vary between sheets.
Excel caches formulas. Press
Ctrl+Shift+Enterfor array formulas, or useF9to recalculate manually. - Performance issues with large datasets.
For >10,000 rows, replace the two-step
COUNTIFmethod with:=LAMBDA(range, SUM(LEN(range) * (range="0")) + COUNTIF(range, ">0"))This uses a lambda function for better speed.
Frequently Asked Questions
How do I count zeros and empty cells together?
Use COUNTIF with "<>"" (for all non-empty cells) and COUNTBLANKS:
=COUNTIF(A2:A100, "<>""") + COUNTBLANKS(A2:A100)
This counts zeros (treated as empty) plus all other values.
Can I use this method with pivot tables?
Yes! Create a calculated field in the pivot table with: Then drag it into the "Values" area. Pivot tables ignore zeros by default, so this forces inclusion.
What if I have mixed numbers and text (e.g., "1")?
Convert text to numbers first:
=COUNTIF(IFERROR(TEXTJOIN(",", TRUE, A2:A100), 0), ">0") + COUNTIF(IFERROR(TEXTJOIN(",", TRUE, A2:A100), 0), "=0")
This converts "1" to 1 but keeps zeros intact.
Why does Excel count empty cells as zero?
Excel’s COUNTIF defaults to treating empty cells as zero because they have a numeric value of 0. To exclude them entirely, use COUNTIF with "<>"" (all non-empty cells) or COUNTIF + COUNTBLANKS.
How do I count zeros in a column filtered by another condition?
Use nested COUNTIFS:
=COUNTIFS(B2:B100, ">0", A2:A100, "=1") + COUNTIFS(B2:B100, "=0", A2:A100, "=1")
This counts zeros only in rows where column A equals "1". Adjust criteria as needed.
Is there a way to count zeros conditionally (e.g., only in a subset)?
Yes! Use FILTER (Excel 365+):
=FILTER(A2:A100, A2:A100="0", 1) + COUNTIF(FILTER(A2:A100, A2:A100>0), ">0")
This returns zeros only where column A matches a condition (e.g., "=1").