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.

Intermediate 18 min read

"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

ABCDE
1DateRegionRepProductAmount
22026-01-05NorthAnnaLaptop2850
32026-01-11SouthBrunoMouse240
42026-01-19NorthDinaMonitor945
52026-02-02EastChenLaptop1900
62026-02-14NorthAnnaMouse120
72026-02-21SouthBrunoLaptop950
82026-03-03EastChenMonitor378

Seven sales in A1:E8. All examples refer to this range.

COUNTIF and COUNTIFS

Formula
COUNTIF(range, criteria)
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], ...)
G2fx=COUNTIF(B2:B8, "North")
ABCDEFG
1DateRegionRepProductAmount
22026-01-05NorthAnnaLaptop28503
32026-01-11SouthBrunoMouse240
42026-01-19NorthDinaMonitor945
52026-02-02EastChenLaptop1900
62026-02-14NorthAnnaMouse120
72026-02-21SouthBrunoLaptop950
82026-03-03EastChenMonitor378

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

Formula
SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
SUMIF(range, criteria, [sum_range])
G2fx=SUMIFS(E2:E8, B2:B8, "North")
ABCDEFG
1DateRegionRepProductAmount
22026-01-05NorthAnnaLaptop28503915
32026-01-11SouthBrunoMouse240
42026-01-19NorthDinaMonitor945
52026-02-02EastChenLaptop1900
62026-02-14NorthAnnaMouse120
72026-02-21SouthBrunoLaptop950
82026-03-03EastChenMonitor378

Total North sales: 2,850 + 945 + 120.

Result: 3915

G3fx=SUMIFS(E2:E8, B2:B8, "North", D2:D8, "Laptop")
ABCDEFG
1DateRegionRepProductAmount
22026-01-05NorthAnnaLaptop2850
32026-01-11SouthBrunoMouse2402850
42026-01-19NorthDinaMonitor945
52026-02-02EastChenLaptop1900
62026-02-14NorthAnnaMouse120
72026-02-21SouthBrunoLaptop950
82026-03-03EastChenMonitor378

North AND Laptop: only Anna's sale on 5 January.

Result: 2850

Watch out. The argument order differs: in SUMIFS the range to add comes first; in the older SUMIF it comes last. Mixing them up is a classic error. Use SUMIFS everywhere and you only need to remember one order.

All ranges in one formula must have the same size. =SUMIFS(E2:E8, B2:B9, "North") returns #VALUE!.

Writing criteria

CriteriaMeaning
"North" or G1Equal to North (not case-sensitive)
">=900"Greater than or equal to 900; operators go inside the quotes
">="&H1Greater 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
Tip. Put criteria in cells rather than typing them into the formula: =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:

G2fx=SUMIFS(E2:E8, A2:A8, ">="&DATE(2026,2,1), A2:A8, "<"&DATE(2026,3,1))
ABCDEFG
1DateRegionRepProductAmount
22026-01-05NorthAnnaLaptop28502,970
32026-01-11SouthBrunoMouse240
42026-01-19NorthDinaMonitor945
52026-02-02EastChenLaptop1900
62026-02-14NorthAnnaMouse120
72026-02-21SouthBrunoLaptop950
82026-03-03EastChenMonitor378

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:

Formula
=SUMIFS(E2:E8, B2:B8, "North") + SUMIFS(E2:E8, B2:B8, "East")
=SUM(SUMIFS(E2:E8, B2:B8, {"North","East"}))
Both return 6,193.

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.

G2fx=SUMPRODUCT((B2:B8="North")*(D2:D8="Laptop")*E2:E8)
ABCDEFG
1DateRegionRepProductAmount
22026-01-05NorthAnnaLaptop28502,850
32026-01-11SouthBrunoMouse240
42026-01-19NorthDinaMonitor945
52026-02-02EastChenLaptop1900
62026-02-14NorthAnnaMouse120
72026-02-21SouthBrunoLaptop950
82026-03-03EastChenMonitor378

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.

Watch out. SUMPRODUCT and array formulas over whole columns (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

H2fx=SUMIFS($E$2:$E$8, $B$2:$B$8, G2)
GHIJ
1RegionSalesOrdersAverage
2North3,91531305
3South11902595
4East227821139

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?

2. How do you write 'greater than the value in H1' as a criteria?

3. Using the lesson data, what does =COUNTIFS(B2:B8,"North",E2:E8,">=900") return?

4. Why not add two COUNTIFS to count rows where Region is North OR Product is Laptop?

5. Which function can apply a condition to a calculated value, such as MONTH of a date column?

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 24 KB