Conditional totals · About 5 minutes
Add up matching rows with SUMIF
SUM adds up everything in a range. SUMIF adds up only the rows that match a condition: a test each row either passes or fails, like "Type is Food".
SUMIF takes three parts inside the parentheses: where to look, what to look for, and what to add up. =SUMIF( reads as "look down B2 to B8 for Food, and add up the matching amounts in C2 to C8".
Text conditions go in quotes, like "Food". So do conditions with a sign, like ">200". Capitals don't matter: "food" finds Food too.
Part of Plus
Free during our founding launch: sign in to unlock this lesson's exercises, the timed practice sets and the rest of Plus. The free lessons stay free, with no account needed.
What SUMIF does
SUMIF adds up only the rows that pass one test. It looks down one column for a match, like every row marked "Bakery", and adds the numbers from another column on those rows.
It saves you from sorting the list or adding cells one by one. When the data changes, the total updates by itself.
How to write SUMIF
=SUMIF(
- range
- The cells to test, like the column of departments B2:B7.
- criteria
- The test each cell must pass. Text goes in quotes, like
"Bakery", and so does a sign with a number, like">20". - sum_range
- The cells to add on the rows that pass. The square brackets mean it's optional: leave it out and SUMIF adds the tested cells themselves.
SUMIF worked example
A shop logs the hours each person worked. In C9, add up the hours worked in Bakery.
| A | B | C | |
|---|---|---|---|
| 1 | Name | Dept | Hours |
| 2 | Maya | Bakery | 32 |
| 3 | Omar | Deli | 28 |
| 4 | Lena | Bakery | 18 |
| 5 | Jon | Produce | 40 |
| 6 | Ivy | Bakery | 25 |
| 7 | Sam | Deli | 36 |
| 8 | |||
| 9 | Bakery | 75 |
=SUMIF( B2:B7, A9, C2:C7)Look down B2 to B7 for the word in A9, and add the hours in C2 to C7 on those rows: 32 + 18 + 25 = 75.Common SUMIF mistakes
The total is 0
Check that the criteria matches the cells exactly. A stray space after "Bakery " in the data, or numbers stored as text in the column you add, both give 0. TRIM and VALUE fix them.
The sign is outside the quotes
Write ">20", with the sign and the number inside one pair of quotes. To use a limit from a cell, join it: ">".
The two ranges start on different rows
Make the tested range and the range to add cover the same rows, like B2:B7 and C2:C7, so each test lines up with its own number.
SUMIF, SUMIFS or COUNTIF?
Use SUMIF for one test. When a row must pass two or more tests, like Bakery and a month, use SUMIFS, which takes the range to add first and then a pair of range and test for each condition.
If you need how many rows match rather than their total, use COUNTIF. It takes the same range and criteria, with nothing to add.
Questions people ask
What does the third part of SUMIF do?
It's the range to add. Leave it out and SUMIF adds the cells it checked, which works when you test the amounts themselves, like =SUMIF(.
Why is my SUMIF returning 0?
Usually the amounts are stored as text, the condition doesn't exactly match the cells because of extra spaces, or the two ranges start on different rows.
Is SUMIF case-sensitive?
No. "north" and "North" match the same rows.
How do I use "greater than" in SUMIF?
Put the sign and number in quotes: =SUMIF(. To read the limit from a cell, use ">"&E1.
Does SUMIF work the same in Google Sheets?
Yes. The parts go in the same order and give the same result.
How do I add up rows that contain a word?
Use * on both sides of the word: =SUMIF( adds every row whose name contains tea, like Green tea or Teapot.