SUMIF and COUNTIF in Excel: Step-by-Step Guide
Most Excel tutorials treat SUMIF and COUNTIF as beginner functions. They're not. The syntax looks approachable, sure, but the criteria rules have traps that catch intermediate users off guard all the time. I've watched analysts with years of Excel experience stare at a formula returning zero, convinced their logic was right, because the failure mode is silent. No error. Just a wrong number. Understanding why these functions behave the way they do is what separates someone who can write the formula from someone who can debug it at 4 PM on a deadline. If you're new to Excel in general, the Excel for Beginners starter guide is worth reading first. But if you've got a basic spreadsheet open and some data to work with, you're ready for this.
The core difference is simple: the COUNTIF function counts how many cells in a range meet a condition. The SUMIF function adds up values in a range based on a condition in a different range. One gives you a count, the other gives you a conditional sum.
The first question isn't what tool to use. It's what does the output need to look like? If the answer is "how many," you want COUNTIF. If it's "how much," you want SUMIF.
|
| SUMIF totals values that meet a condition. COUNTIF counts them. Both belong in your everyday Excel toolkit. |
Step 1: Build Your First COUNTIF Formula
Understanding the COUNTIF syntax: range and criteria
COUNTIF takes two arguments: COUNTIF(range, criteria). The criteria range is the column you're checking. The criteria is what you're checking it against.
Say you're working with a Regional Logistics Orders Q1 2025 sheet. Column B holds carrier names ("FedEx," "UPS," "DHL") and you want to know how many shipments went through FedEx. Your formula looks like this:
=COUNTIF(B2:B500, "FedEx")
Excel scans every cell in B2:B500, counts the ones that exactly match "FedEx," and returns the number. Case doesn't matter: "fedex" and "FEDEX" both match. What does matter is that the text in your criteria range is consistent.
A trailing space after "FedEx" in even a single row will silently break the match. No error, just a wrong count. If you're pulling data from an external source, run TRIM() on your criteria range before writing any COUNTIF against it.
Using logical operators and wildcard characters in your criteria
You're not limited to exact matches. Logical operators let you write criteria like ">500" to count cells with values above 500. Wildcard characters let you do partial matches: the asterisk (*) matches any sequence of characters, so "Fed*" matches "FedEx," "FedGround," or anything else starting with "Fed." The question mark (?) matches exactly one character.
A COUNTIF partial match wildcard is genuinely useful when your data isn't perfectly clean. =COUNTIF(B2:B500, "*Express*") catches any carrier name containing the word "Express," including variations you didn't anticipate.
The syntax for combining a cell reference with a logical operator trips people up constantly. ">500" works. ">"&A2 works. >A2 silently returns zero. And ">"&"500" technically works but is pointless. Know the four variants. Only two are actually useful.
Step 2: Write a SUMIF Formula to Add Up Only the Values You Care About
Once you've got COUNTIF working, SUMIF is a short step. You're adding one more argument that tells Excel what to add up, not just what to count.
Where the sum range fits into the SUMIF syntax
SUMIF takes three arguments: SUMIF(range, criteria, sum_range). The first two work exactly like COUNTIF. The third, the sum range, is the column containing the values you want to add. It needs to be the same size as your criteria range and aligned row-for-row.
If your criteria range is B2:B500, your sum range should also start at row 2. Mismatched range sizes don't always throw an error: Excel can silently offset the calculation and return a wrong number with no warning at all.
Back to the logistics sheet: column B has carrier names, column E has shipment values in dollars. To get the total value shipped through FedEx:
=SUMIF(B2:B500, "FedEx", E2:E500)
The formula returns the correct total (assuming your values column contains actual numbers, not numbers stored as text) and updates automatically when the data changes.
Using SUMIF with text criteria and date ranges
A SUMIF text criteria formula works exactly as shown above. Wildcards work here too: "*Express*" as your criteria sums values for any carrier matching that pattern.
Date criteria is where things get less intuitive. Excel stores dates as serial numbers internally, and SUMIF compares against those underlying values, not what you see formatted in the cell. A SUMIF date range formula using DATE() works reliably:
=SUMIF(C2:C500, ">"&DATE(2025,12,31), E2:E500)
DATE() returns a serial number Excel can compare directly. Hardcoding a date string like ">12/31/2025" is risky: date formatting varies by locale and can produce unexpected results depending on a user's regional settings.
Both Microsoft 365 and Google Sheets support this syntax identically, including wildcard characters, logical operators, and date handling. One less thing to worry about if your team works across both platforms.
Step 3: When to Upgrade to SUMIFS or COUNTIFS for Multiple Criteria
With SUMIF and COUNTIF working on your data, you'll quickly hit a situation where one condition isn't enough. That's where SUMIFS and COUNTIFS come in.
The argument order flips in SUMIFS: sum_range comes first, not last. =SUMIFS(E2:E500, B2:B500, "FedEx", D2:D500, "West") sums shipment values where the carrier is FedEx and the region is West. Both conditions must be true (AND logic, not OR). You can stack up to 127 criteria pairs, though more than four or five usually signals a data structure problem worth addressing before it compounds.
There are also situations where a PivotTable is the smarter tool. If you need to calculate a conditional average in Excel across multiple groupings at once, or if your criteria are going to change frequently, a PivotTable gives you that interactivity without rewriting formulas. The Excel Formulas and Functions for Beginners guide covers where formulas end and pivot tables begin, which is a useful boundary to understand early.
Common SUMIF and COUNTIF Mistakes and How to Fix Them
The most dangerous failure mode is SUMIF or SUMIFS returning zero when the formula looks completely correct. Nine times out of ten, it's numbers stored as text in the criteria range: Excel can't match a number to a text string, so it returns zero without any error flag. Fix it at the source if you can by enforcing data types in Power Query before the data hits your sheet. If that's not an option, wrap the criteria range in VALUE(), or select the column and use the "Convert to Number" prompt that appears on the warning triangle.
The second common issue is the sum range not matching the criteria range in size. Even a one-row offset produces wrong results without any warning. Always verify that both ranges start and end on the same rows.
Date comparisons trip up beginners because the formatted display and the stored value are two different things. Use DATE() or a cell reference in your criteria rather than a hardcoded date string.
And if COUNTIF is undercounting when you're sure the values match, run TRIM() and CLEAN() on your criteria range. Invisible characters, the kind that come in when data is copied from a web page or exported from legacy software, are exactly as frustrating as they sound. A non-breaking space is indistinguishable from a regular space in the cell view and will silently break every match. For deeper context on how Excel handles conditional logic generally, the Introduction to IF Function quick reference is a useful companion: a lot of the same thinking applies.
Frequently Asked Questions
What is the difference between SUMIF and COUNTIF in Excel?
COUNTIF counts how many cells in a range meet your condition. SUMIF adds up values in a separate range based on that same condition. Use COUNTIF when the output is a count; use SUMIF when the output is a total.
Why is my SUMIF formula returning zero?
The most common cause is numbers stored as text in your criteria range: Excel can't match a number to a text string, so it returns zero without any error. Use the "Convert to Number" option or wrap the range in VALUE(). A mismatched sum range size and invisible characters like trailing spaces are the next most likely culprits.
When should I use SUMIFS instead of SUMIF?
Use SUMIFS any time you need more than one condition. It handles multiple criteria ranges with AND logic, meaning all conditions must be true for a row to be included. Just remember the argument order flips: sum_range comes first in SUMIFS, not last like in SUMIF.
Can SUMIF and COUNTIF be used in Google Sheets?
Yes, the syntax is identical in Google Sheets. SUMIF, COUNTIF, SUMIFS, and COUNTIFS all work the same way, including wildcard characters and logical operators in criteria. Date handling follows the same serial number logic as Microsoft Excel.
Join the conversation