COUNTIF and SUMIF in Numbers: Count with a Condition
The examples use this table.
| A | B | C | |
|---|---|---|---|
| 1 | Product | Price | Qty |
| 2 | Apple | 4 | 10 |
| 3 | Pear | 6 | 5 |
| 4 | Kiwi | 12 | 2 |
| 5 | Grape | 8 | 3 |
COUNTIF: counting cells
COUNTIF counts the cells in a range that meet one condition. Here: how many prices are higher than 5.
=COUNTIF(B2:B5,">5")Result: 3
SUMIF: adding with a condition
SUMIF tests one range and adds up the values of another range. Here: the quantities of products with a price higher than 5.
=SUMIF(B2:B5,">5",C2:C5)Result: 10
Several conditions: COUNTIFS
COUNTIFS counts the rows for which several conditions are true at the same time. You give a range and a condition for each.
=COUNTIFS(B2:B5,">5",C2:C5,"<5")Result: 2
An average with a condition
AVERAGEIF returns the average of only the cells that meet a condition.
=AVERAGEIF(B2:B5,">5",C2:C5)Result: 3.3333
Frequently asked questions
What is the difference between COUNTIF and SUMIF?
COUNTIF counts how many cells match. SUMIF adds up the values of those cells.
How do I write a condition like “greater than 5”?
Put the comparison between quotation marks: ">5".
Can I count text?
Yes, for example COUNTIF(A2:A5, "Kiwi") counts the cells with exactly that text.
Functions in this article
Practise it yourself
Type the formula yourself in a real exercise and see right away if your answer is correct. The first exercises are free.
Start practising