Excel course · Lesson 18 of 34
Counting and summing with criteria: COUNTIFS, SUMIFS, SUMPRODUCT
Count and add values that meet conditions with COUNTIF, COUNTIFS, SUMIF, SUMIFS, AVERAGEIFS and SUMPRODUCT, including dates, wildcards and OR logic.
"How much did North sell in February?" "How many invoices are over 1,000?" "What is the average order for laptops?" Questions like these need a total or count of only the rows that meet certain conditions. The IFS family of functions answers them in one formula, and SUMPRODUCT handles the cases they cannot.
The data
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Date | Region | Rep | Product | Amount |
| 2 | 2026-01-05 | North | Anna | Laptop | 2850 |
| 3 | 2026-01-11 | South | Bruno | Mouse | 240 |
| 4 | 2026-01-19 | North | Dina | Monitor | 945 |
| 5 | 2026-02-02 | East | Chen | Laptop | 1900 |
| 6 | 2026-02-14 | North | Anna | Mouse | 120 |
| 7 | 2026-02-21 | South | Bruno | Laptop | 950 |
| 8 | 2026-03-03 | East | Chen | Monitor | 378 |
Seven sales in A1:E8. All examples refer to this range.
COUNTIF and COUNTIFS
COUNTIF(range, criteria)
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], ...)| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Date | Region | Rep | Product | Amount | ||
| 2 | 2026-01-05 | North | Anna | Laptop | 2850 | 3 | |
| 3 | 2026-01-11 | South | Bruno | Mouse | 240 | ||
| 4 | 2026-01-19 | North | Dina | Monitor | 945 | ||
| 5 | 2026-02-02 | East | Chen | Laptop | 1900 | ||
| 6 | 2026-02-14 | North | Anna | Mouse | 120 | ||
| 7 | 2026-02-21 | South | Bruno | Laptop | 950 | ||
| 8 | 2026-03-03 | East | Chen | Monitor | 378 |
Three sales were made in North.
Result: 3
COUNTIFS accepts several range/criteria pairs, and counts only rows where all conditions are met: =COUNTIFS(B2:B8, "North", E2:E8, ">=900") returns 2 (Anna's laptop and Dina's monitor). COUNTIF is the one-condition version; since COUNTIFS does everything COUNTIF does, many people simply always use COUNTIFS.
SUMIF and SUMIFS
SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
SUMIF(range, criteria, [sum_range])| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Date | Region | Rep | Product | Amount | ||
| 2 | 2026-01-05 | North | Anna | Laptop | 2850 | 3915 | |
| 3 | 2026-01-11 | South | Bruno | Mouse | 240 | ||
| 4 | 2026-01-19 | North | Dina | Monitor | 945 | ||
| 5 | 2026-02-02 | East | Chen | Laptop | 1900 | ||
| 6 | 2026-02-14 | North | Anna | Mouse | 120 | ||
| 7 | 2026-02-21 | South | Bruno | Laptop | 950 | ||
| 8 | 2026-03-03 | East | Chen | Monitor | 378 |
Total North sales: 2,850 + 945 + 120.
Result: 3915
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Date | Region | Rep | Product | Amount | ||
| 2 | 2026-01-05 | North | Anna | Laptop | 2850 | ||
| 3 | 2026-01-11 | South | Bruno | Mouse | 240 | 2850 | |
| 4 | 2026-01-19 | North | Dina | Monitor | 945 | ||
| 5 | 2026-02-02 | East | Chen | Laptop | 1900 | ||
| 6 | 2026-02-14 | North | Anna | Mouse | 120 | ||
| 7 | 2026-02-21 | South | Bruno | Laptop | 950 | ||
| 8 | 2026-03-03 | East | Chen | Monitor | 378 |
North AND Laptop: only Anna's sale on 5 January.
Result: 2850
All ranges in one formula must have the same size. =SUMIFS(E2:E8, B2:B9, "North") returns #VALUE!.
Writing criteria
| Criteria | Meaning |
|---|---|
| "North" or G1 | Equal to North (not case-sensitive) |
| ">=900" | Greater than or equal to 900; operators go inside the quotes |
| ">="&H1 | Greater than or equal to the value in H1; join the operator with & |
| "<>Mouse" | Not equal to Mouse |
| "Lap*" | Starts with Lap (* = any characters) |
| "top" | Contains top |
| "?????" | Exactly five characters (? = one character) |
| "" | Empty cell |
| "<>" | Not empty |
=SUMIFS($E$2:$E$8, $B$2:$B$8, G2) with region names in G2:G4 gives a summary table that you can fill down. Lock the data ranges with $ so they do not move.Criteria on dates
To total February 2026, give a start and an end condition on the same date column:
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Date | Region | Rep | Product | Amount | ||
| 2 | 2026-01-05 | North | Anna | Laptop | 2850 | 2,970 | |
| 3 | 2026-01-11 | South | Bruno | Mouse | 240 | ||
| 4 | 2026-01-19 | North | Dina | Monitor | 945 | ||
| 5 | 2026-02-02 | East | Chen | Laptop | 1900 | ||
| 6 | 2026-02-14 | North | Anna | Mouse | 120 | ||
| 7 | 2026-02-21 | South | Bruno | Laptop | 950 | ||
| 8 | 2026-03-03 | East | Chen | Monitor | 378 |
February: 1,900 + 120 + 950.
Result: 2,970
Using < the first day of the next month is safer than <= the last day, because it also catches dates that carry a time of day. With the month start in H1, write ">="&H1 and "<"&EDATE(H1,1) to make the formula reusable. Do not write ">=2026-02-01" inside quotes; it depends on regional date settings.
AVERAGEIFS, MAXIFS and MINIFS
=AVERAGEIFS(E2:E8, D2:D8, "Laptop")returns 1,900, the average laptop sale.=MAXIFS(E2:E8, C2:C8, "Chen")returns 1,900, Chen's largest sale. Available in Excel 2019 and later.=MINIFS(E2:E8, B2:B8, "South")returns 240.
OR conditions
SUMIFS and COUNTIFS combine conditions with AND. For OR on the same column (North or East), add two SUMIFS, or pass an array constant and wrap in SUM:
=SUMIFS(E2:E8, B2:B8, "North") + SUMIFS(E2:E8, B2:B8, "East")
=SUM(SUMIFS(E2:E8, B2:B8, {"North","East"}))Never add two COUNTIFS for OR conditions on different columns (Region = North OR Product = Laptop): rows meeting both conditions are counted twice. That is a job for SUMPRODUCT.
SUMPRODUCT: criteria on anything
SUMPRODUCT multiplies arrays item by item and adds the results. Comparisons inside it return TRUE/FALSE arrays; multiplying them converts them to 1s and 0s. This lets you build any condition, including calculations on the ranges themselves, which the IFS functions do not allow.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Date | Region | Rep | Product | Amount | ||
| 2 | 2026-01-05 | North | Anna | Laptop | 2850 | 2,850 | |
| 3 | 2026-01-11 | South | Bruno | Mouse | 240 | ||
| 4 | 2026-01-19 | North | Dina | Monitor | 945 | ||
| 5 | 2026-02-02 | East | Chen | Laptop | 1900 | ||
| 6 | 2026-02-14 | North | Anna | Mouse | 120 | ||
| 7 | 2026-02-21 | South | Bruno | Laptop | 950 | ||
| 8 | 2026-03-03 | East | Chen | Monitor | 378 |
Same answer as SUMIFS: only rows where both tests are 1 keep their amount.
Result: 2,850
- Criteria on a calculated value — sales in January of any year:
=SUMPRODUCT((MONTH(A2:A8)=1)*E2:E8)returns 4,035. - OR across columns — count rows that are North or Laptop, without double counting:
=SUMPRODUCT(--(((B2:B8="North")+(D2:D8="Laptop"))>0))returns 5. - Weighted totals — on an order sheet with quantities in B2:B5 and unit prices in C2:C5,
=SUMPRODUCT(B2:B5, C2:C5)multiplies quantity by price row by row and adds the results: the order value without a helper column.
The double minus -- converts TRUE/FALSE to 1/0 when there is no multiplication to do it. In Microsoft 365 you can also use SUM instead of SUMPRODUCT for these array calculations, because dynamic array Excel evaluates arrays natively. In Excel 2019 and earlier, SUM needs Ctrl+Shift+Enter, while SUMPRODUCT does not.
A:A) calculate a million rows each time and can make a workbook slow. Use exact ranges or Excel table columns. SUMIFS, by contrast, handles whole columns efficiently.Two everyday tricks with COUNTIFS
Flag duplicates
In a helper column next to a list of invoice numbers, =COUNTIFS($A$2:$A$500, A2)>1 returns TRUE for every invoice number that appears more than once. Use the same test in a conditional formatting rule to colour the duplicates, as shown in Conditional formatting, including formula-based rules.
Number the occurrences
To number each rep's sales 1, 2, 3 in the order they appear, use an expanding range: =COUNTIFS($C$2:C2, C2) in row 2, filled down. The first reference is locked at row 2 while the second end moves down, so each row counts only the rows above it plus itself. Anna's first sale gets 1 and her sale on 14 February gets 2. This running count is handy for building unique keys such as Anna-2 for lookups.
Troubleshooting criteria formulas
- Result is 0 but you expected a total: check for trailing spaces in the data (
"North "is not"North"), or numbers stored as text in the sum range. TRIM and Convert to Number fix these (Text cleanup: TRIM, CLEAN, TEXTSPLIT, Flash Fill and Text to Columns). - #VALUE!: the ranges are different sizes, or a criteria range refers to a closed external workbook (SUMIFS and COUNTIFS cannot read closed files; SUMPRODUCT can).
- Wildcards not wanted: to search for a real asterisk or question mark, put a tilde before it:
"~*". - Dates not matched: the date column contains text. Test a cell with
=ISNUMBER(A2); real dates return TRUE.
Summary table in practice
| G | H | I | J | |
|---|---|---|---|---|
| 1 | Region | Sales | Orders | Average |
| 2 | North | 3,915 | 3 | 1305 |
| 3 | South | 1190 | 2 | 595 |
| 4 | East | 2278 | 2 | 1139 |
H2 =SUMIFS($E$2:$E$8,$B$2:$B$8,G2), I2 =COUNTIFS($B$2:$B$8,G2), J2 =H2/I2, all filled down.
Result: 3,915
This is the formula-based alternative to a PivotTable (PivotTables: summarise thousands of rows in seconds). It updates instantly without refreshing and can be laid out exactly as you like. In Microsoft 365, GROUPBY can build the whole summary with one formula.
Check yourself
1. In SUMIFS, which argument comes first?
SUMIFS(sum_range, criteria_range1, criteria1, …).
2. How do you write 'greater than the value in H1' as a criteria?
The operator is text; join it to the cell value with &.
3. Using the lesson data, what does =COUNTIFS(B2:B8,"North",E2:E8,">=900") return?
North rows are 2,850, 945 and 120; two of them are at least 900.
4. Why not add two COUNTIFS to count rows where Region is North OR Product is Laptop?
Anna's North laptop sale would be counted once by each COUNTIFS.
5. Which function can apply a condition to a calculated value, such as MONTH of a date column?
SUMIFS criteria ranges must be real ranges; SUMPRODUCT accepts any array expression.