Counting and adding with conditions: COUNTIFS and SUMIFS
Answer everyday business questions in one formula: count matching rows with COUNTIF and COUNTIFS, add up matching values with SUMIF and SUMIFS, and find conditional averages with AVERAGEIF and AVERAGEIFS.
🎯 By the end of this lesson you will be able to:
- Count rows that match one or more conditions
- Add up and average values for rows that match conditions
- Use cell references and comparison operators in criteria
Outline
What you'll learn and why it matters
*How many orders did the North region place? What were Asha's total sales? What is the average order value for backpacks?* Managers ask questions like these all day. COUNTIFS and SUMIFS answer them in one formula each, and they update the moment new data is added.
COUNTIF and COUNTIFS: how many?
=COUNTIF(range, criteria) counts the cells in a range that match. COUNTIFS takes several *range, criteria* pairs and counts rows where all match:
Worksheet: Sales
| Row | A | B | C | D | E | F | G | H | I |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Region | Salesperson | Product | Units | Price | Total | Question | Answer | |
| 2 | West | Asha | Sketchbook | 11 | 300 | 3300 | Orders from North | 4 | |
| 3 | North | Meera | Pen set | 4 | 250 | 1000 | Orders by Meera | 3 | |
| 4 | West | Ravi | Sketchbook | 3 | 300 | 900 | North orders by Meera | 2 | |
| 5 | North | Sara | Notebook | 9 | 120 | 1080 | Orders of 5+ units | 5 | |
| 6 | East | Ravi | Notebook | 2 | 120 | 240 | |||
| 7 | North | Meera | Pen set | 8 | 250 | 2000 | |||
| 8 | East | Meera | Backpack | 2 | 1500 | 3000 | |||
| 9 | North | Asha | Desk lamp | 4 | 1200 | 4800 | |||
| 10 | South | Kofi | Notebook | 11 | 120 | 1320 | |||
| 11 | West | Ravi | Water bottle | 10 | 400 | 4000 |
Formulas (green cells)
- F2 =D2*E2 → 3300
- I2 =COUNTIF(A2:A11,"North") → 4
- F3 =D3*E3 → 1000
- I3 =COUNTIF(B2:B11,"Meera") → 3
- F4 =D4*E4 → 900
- I4 =COUNTIFS(A2:A11,"North",B2:B11,"Meera") → 2
- F5 =D5*E5 → 1080
- I5 =COUNTIF(D2:D11,">=5") → 5
- F6 =D6*E6 → 240
- F7 =D7*E7 → 2000
- F8 =D8*E8 → 3000
- F9 =D9*E9 → 4800
- F10 =D10*E10 → 1320
- F11 =D11*E11 → 4000
| Criteria | Matches |
|---|---|
"North" | Cells equal to North (not case-sensitive) |
">=5" | Numbers of 5 or more (comparisons go inside the quotes) |
"<>West" | Everything except West |
"*lamp*" | Text containing lamp (* means any characters) |
H2 or ">="&H2 | A value typed in another cell, so the question can change |
SUMIF and SUMIFS: how much?
=SUMIFS(sum_range, criteria_range1, criteria1, …) adds up the values in sum_range for the rows that match. Note the order: the column to add comes first.
Worksheet: Sales
| Row | A | B | C | D | E | F | G | H | I |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Region | Salesperson | Product | Units | Price | Total | Question | Answer | |
| 2 | West | Asha | Sketchbook | 11 | 300 | 3300 | Total sales | 21640 | |
| 3 | North | Meera | Pen set | 4 | 250 | 1000 | Sales in North | 8880 | |
| 4 | West | Ravi | Sketchbook | 3 | 300 | 900 | Asha's sales | 8100 | |
| 5 | North | Sara | Notebook | 9 | 120 | 1080 | Notebook units | 22 | |
| 6 | East | Ravi | Notebook | 2 | 120 | 240 | Avg Pen set order | 1500 | |
| 7 | North | Meera | Pen set | 8 | 250 | 2000 | |||
| 8 | East | Meera | Backpack | 2 | 1500 | 3000 | |||
| 9 | North | Asha | Desk lamp | 4 | 1200 | 4800 | |||
| 10 | South | Kofi | Notebook | 11 | 120 | 1320 | |||
| 11 | West | Ravi | Water bottle | 10 | 400 | 4000 |
Formulas (green cells)
- F2 =D2*E2 → 3300
- I2 =SUM(F2:F11) → 21640
- F3 =D3*E3 → 1000
- I3 =SUMIFS(F2:F11,A2:A11,"North") → 8880
- F4 =D4*E4 → 900
- I4 =SUMIFS(F2:F11,B2:B11,"Asha") → 8100
- F5 =D5*E5 → 1080
- I5 =SUMIFS(D2:D11,C2:C11,"Notebook") → 22
- F6 =D6*E6 → 240
- I6 =AVERAGEIF(C2:C11,"Pen set",F2:F11) → 1500
- F7 =D7*E7 → 2000
- F8 =D8*E8 → 3000
- F9 =D9*E9 → 4800
- F10 =D10*E10 → 1320
- F11 =D11*E11 → 4000
Let people change the question
Put the criteria in cells and refer to them. Now anyone can type a different region or salesperson and the answer updates:
Worksheet: Sales
| Row | A | B | C | D | E | F | G | H | I |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Region | Salesperson | Product | Units | Price | Total | Region | North | |
| 2 | West | Asha | Sketchbook | 11 | 300 | 3300 | Salesperson | Meera | |
| 3 | North | Meera | Pen set | 4 | 250 | 1000 | Orders | 2 | |
| 4 | West | Ravi | Sketchbook | 3 | 300 | 900 | Sales | 3000 | |
| 5 | North | Sara | Notebook | 9 | 120 | 1080 | |||
| 6 | East | Ravi | Notebook | 2 | 120 | 240 | |||
| 7 | North | Meera | Pen set | 8 | 250 | 2000 | |||
| 8 | East | Meera | Backpack | 2 | 1500 | 3000 | |||
| 9 | North | Asha | Desk lamp | 4 | 1200 | 4800 | |||
| 10 | South | Kofi | Notebook | 11 | 120 | 1320 | |||
| 11 | West | Ravi | Water bottle | 10 | 400 | 4000 |
Formulas (green cells)
- F2 =D2*E2 → 3300
- F3 =D3*E3 → 1000
- I3 =COUNTIFS(A2:A11,I1,B2:B11,I2) → 2
- F4 =D4*E4 → 900
- I4 =SUMIFS(F2:F11,A2:A11,I1,B2:B11,I2) → 3000
- F5 =D5*E5 → 1080
- F6 =D6*E6 → 240
- F7 =D7*E7 → 2000
- F8 =D8*E8 → 3000
- F9 =D9*E9 → 4800
- F10 =D10*E10 → 1320
- F11 =D11*E11 → 4000
Practice
Guided exercise
Regional report
In the ten orders, count the orders from West and add up West's total sales.
- Count:
=COUNTIF(A2:A11,"West"). - Sum:
=SUMIFS(F2:F11,A2:A11,"West")(the Total column first).
Show the solution
Worksheet: Sales
| Row | A | B | C | D | E | F | G | H | I |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Region | Salesperson | Product | Units | Price | Total | Question | Answer | |
| 2 | West | Asha | Sketchbook | 11 | 300 | 3300 | West orders | 3 | |
| 3 | North | Meera | Pen set | 4 | 250 | 1000 | West sales | 8200 | |
| 4 | West | Ravi | Sketchbook | 3 | 300 | 900 | |||
| 5 | North | Sara | Notebook | 9 | 120 | 1080 | |||
| 6 | East | Ravi | Notebook | 2 | 120 | 240 | |||
| 7 | North | Meera | Pen set | 8 | 250 | 2000 | |||
| 8 | East | Meera | Backpack | 2 | 1500 | 3000 | |||
| 9 | North | Asha | Desk lamp | 4 | 1200 | 4800 | |||
| 10 | South | Kofi | Notebook | 11 | 120 | 1320 | |||
| 11 | West | Ravi | Water bottle | 10 | 400 | 4000 |
Formulas (green cells)
- F2 =D2*E2 → 3300
- I2 =COUNTIF(A2:A11,"West") → 3
- F3 =D3*E3 → 1000
- I3 =SUMIFS(F2:F11,A2:A11,"West") → 8200
- F4 =D4*E4 → 900
- F5 =D5*E5 → 1080
- F6 =D6*E6 → 240
- F7 =D7*E7 → 2000
- F8 =D8*E8 → 3000
- F9 =D9*E9 → 4800
- F10 =D10*E10 → 1320
- F11 =D11*E11 → 4000
How to get there: COUNTIF counts the matching rows; SUMIFS adds the Total column for those same rows. Checking by eye against the list is a good habit while you learn.
Your turn
Big orders
How many orders have a total of 2,000 or more, and what do they add up to?
Show the solution
Worksheet: Sales
| Row | A | B | C | D | E | F | G | H | I |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Region | Salesperson | Product | Units | Price | Total | Question | Answer | |
| 2 | West | Asha | Sketchbook | 11 | 300 | 3300 | Orders ≥ 2000 | 5 | |
| 3 | North | Meera | Pen set | 4 | 250 | 1000 | Their total | 17100 | |
| 4 | West | Ravi | Sketchbook | 3 | 300 | 900 | |||
| 5 | North | Sara | Notebook | 9 | 120 | 1080 | |||
| 6 | East | Ravi | Notebook | 2 | 120 | 240 | |||
| 7 | North | Meera | Pen set | 8 | 250 | 2000 | |||
| 8 | East | Meera | Backpack | 2 | 1500 | 3000 | |||
| 9 | North | Asha | Desk lamp | 4 | 1200 | 4800 | |||
| 10 | South | Kofi | Notebook | 11 | 120 | 1320 | |||
| 11 | West | Ravi | Water bottle | 10 | 400 | 4000 |
Formulas (green cells)
- F2 =D2*E2 → 3300
- I2 =COUNTIF(F2:F11,">=2000") → 5
- F3 =D3*E3 → 1000
- I3 =SUMIFS(F2:F11,F2:F11,">=2000") → 17100
- F4 =D4*E4 → 900
- F5 =D5*E5 → 1080
- F6 =D6*E6 → 240
- F7 =D7*E7 → 2000
- F8 =D8*E8 → 3000
- F9 =D9*E9 → 4800
- F10 =D10*E10 → 1320
- F11 =D11*E11 → 4000
How to get there: The criteria range and the sum range can be the same column. The comparison goes inside quotes: ">=2000".
Common mistakes
Putting the sum range last in SUMIFS
You see: Wrong totals or an error
Fix: SUMIFS: sum range first, then criteria pairs.
Ranges of different sizes
You see: #VALUE!
Fix: Every range must cover the same rows, such as 2 to 11.
Writing >=5 without quotes
You see: Excel reports a formula error
Fix: Put comparisons in quotes: ">=5".
Extra spaces in the data, like North
You see: Rows that look matching are not counted
Fix: Clean the data with TRIM (lesson 7).
Recap
- COUNTIF counts matching cells; COUNTIFS counts rows matching every condition.
- SUMIFS(sum_range, range1, criteria1, …) adds values for matching rows; AVERAGEIF and AVERAGEIFS average them.
- Criteria can be text, comparisons in quotes like ">=5", wildcards, or cell references.
- Referring to criteria cells turns a formula into a reusable report.
Key terms
- Criteria
- The condition a cell must meet to be counted or added, such as "North" or ">=5".
- Sum range
- The column of numbers SUMIFS adds up for the matching rows.
- Wildcard
- * (any characters) or ? (one character) in text criteria.
Check your understanding
Answer all 4 questions, then check your answers to see an explanation for each one.
1. Which formula adds up column F for rows where column A is South?
2. How do you count values of 100 or more in B2:B50?
3. What does COUNTIFS count?
4. Why put criteria like a region name in its own cell?
Mark this lesson complete
Finished this lesson?
When you have worked through the examples and exercises, mark it complete to save your progress.