Learning path · Level 4 · Tutorial 5

Summarize Matching Records with SUMIF and COUNTIF

Calculate category sales totals and matching-record counts with SUMIF and COUNTIF in Excel or Calc. Use text and numeric criteria, keep ranges aligned when copying formulas, and check the results against the underlying records without relying on visible filter results.

  • Level: Intermediate
  • Duration: 18 min
  • 8 steps
Start tutorial Back to the path
Summarize Matching Records with SUMIF and COUNTIF

What you will go through

  1. Choose a Count or a Total Choose whether a category question needs a matching-record count or a matching-amount total, then create the Sales worksheet used throughout the tutorial. 2 min
  2. Count Records for a Category Count matching category records with COUNTIF, using both quoted text and a category-summary cell reference. 2 min
  3. Total Amounts from Matching Rows Build a category SUMIF formula and keep criteria and amount ranges aligned so matching source records contribute the correct sales amounts. 3 min
  4. Use Numeric Conditions Count and total source-record amounts using literal numeric criteria, then compare inclusive and strict boundaries. 2 min
  5. Control the Condition from a Cell Replace a hard-coded numeric comparison with a criterion built from an operator and the threshold in H2. 2 min
  6. Copy a Reliable Category Summary Anchor COUNTIF and SUMIF source ranges so a category summary can be copied down reliably. 3 min
  7. Test Missing Matches and Filtered Rows Test zero-result cases and confirm that conditional formulas still evaluate all referenced source records when a worksheet filter hides some rows. 2 min
  8. Reconcile and Verify the Summary Complete a final audit of the category summary by reconciling counts and amounts with the source records. 3 min

What you will learn

  • Count records for a category or numeric condition with COUNTIF.
  • Total US dollar amounts for matching records with correctly aligned SUMIF ranges.
  • Build comparison criteria from an operator and a referenced threshold cell.
  • Copy a category summary while keeping source ranges fixed and criterion references appropriate.
  • Check a known match and a no-match case, then reconcile a complete category summary with source totals and record counts.

Before you start

  • Clean a Sales Register Without Losing Source Data
  • Write Budget Formulas with Cell References
  • Calculate and Check Totals and Averages
  • Flag Spending Limits with IF

Step 1 of 8

Choose a Count or a Total

Choose whether a category question needs a matching-record count or a matching-amount total, then create the Sales worksheet used throughout the tutorial.

Decide what to summarize

One condition, two useful questions

A conditional summary starts by choosing the question.

  • Use COUNTIF when you need to know how many source records meet one condition.
  • Use SUMIF when you need to know how much the matching records contribute.

For example, Stationery can appear in several source records. A count treats each matching row as one record; a total combines the amounts from those same matching rows. Later, you will build the formulas that produce these answers.

A diagram showing repeated matching source rows feeding both a record count and an amount total.

The same matching source records can answer two different questions: how many records match, and how much their amounts add up.

Set up the shared worksheet

Create the source records

On your computer, create a new worksheet named Sales. Enter the following source records in cells A1:B10 exactly as shown. The header row is not a source record.

Enter the amounts as numbers without typed currency symbols. Format B2:B10 as US dollars with two decimal places if your application supports that format.

Source data

Enter these values in A1:B10 on the Sales worksheet.

Nine source records occupy rows 2 through 10.
RowCategoryAmount (USD)
1CategoryAmount (USD)
2Stationery40
3Accessories120
4Storage200
5Stationery100
6Accessories80
7Stationery50
8Storage150
9Accessories0
10Stationery60

Prepare the category summary

Next, create a separate category summary in D1:F5. Leave the calculation cells empty for now. This layout keeps summary results separate from the source records.

Format future values in F2:F5 as US dollars with two decimal places. Counts in E2:E5 should be displayed as whole numbers.

Summary layout

Enter the labels and category names shown below. Do not change the source records while working through this tutorial.

The summary will be completed in later steps.
CellEnterPurpose
D1CategorySummary header
E1Matching recordsSummary header
F1Sales (USD)Summary header
D2StationeryCategory to summarize
D3AccessoriesCategory to summarize
D4StorageCategory to summarize
D5All categoriesReserved total label

Quick check

Check your setup and purpose

Match each prompt or source-range description to the correct answer.

Tap an item and then its matching pair.

Step 2 of 8

Count Records for a Category

Count matching category records with COUNTIF, using both quoted text and a category-summary cell reference.

Count records, not dollars

What COUNTIF counts

A category may appear in several source records. COUNTIF answers how many records meet one condition; it does not add their amounts.

Its structure is COUNTIF(criteria range, criterion). For this worksheet, the criteria range is A2:A10, not A1:A10, so the Category header is excluded. Every source row whose category meets the criterion contributes one—regardless of whether its amount is positive, zero, or large.

One match per source row

A nine-row source-record table with four category cells highlighted to show that each matching row contributes one to a COUNTIF result.

For Stationery, source rows 2, 5, 7, and 10 each contribute one matching record.

Tip

Keep the question focused

A zero amount does not remove a source record from a category count. COUNTIF examines the selected criteria range, so a category record still counts even when its amount is 0.

Count with a literal criterion

Use a quoted category label

A literal text criterion uses straight double quotation marks. To test Stationery, enter the comma version below in temporary practice cell H4.

If your Excel or Calc locale uses semicolons, use =COUNTIF(A2:A10;"Stationery") instead. The accepted separator depends on your application and locale settings.

Count the Stationery records

Enter this formula in H4.

excel
=COUNTIF(A2:A10,"Stationery")
Expected output
4

The result is a whole-number record count.

Example

Interpret the result

The criterion selects the four Stationery source records. It does not inspect or total the corresponding values in column B; that is a different task.

Count with a referenced criterion

Use the category summary cell

A criterion can also be a cell reference. D2 already contains the category label Stationery, so enter the formula below in E2 of the category summary.

With a semicolon separator, use =COUNTIF(A2:A10;D2). This produces the same count while letting the category label live in the summary cell rather than inside the formula.

Count the category named in D2

Enter this formula in E2.

excel
=COUNTIF(A2:A10,D2)
Expected output
4

D2 contains Stationery, so the result is a whole-number count.

Check the results against the source records

Complete both COUNTIF forms

Finish the criteria in these two formulas. Then enter the completed formulas in the indicated worksheet cells.

Practice: literal and referenced criteria

Complete the missing criteria.

excel
H4: =COUNTIF(A2:A10,)
E2: =COUNTIF(A2:A10,)

Audit the category counts

In your worksheet, verify the count in both H4 and E2. Identify the four Stationery source-row numbers. Then use H5 to count Accessories with a literal category criterion. Report the Accessories count and explain why its zero amount does or does not change that count.

Write at least 60 characters (0/60).

Step 3 of 8

Total Amounts from Matching Rows

Build a category SUMIF formula and keep criteria and amount ranges aligned so matching source records contribute the correct sales amounts.

Build a category SUMIF

Select records, then add their amounts

On the existing Sales worksheet, SUMIF answers a different question from COUNTIF: it adds the amounts contributed by matching source records.

Its three parts are:

  1. criteria range — where to test for a match
  2. criterion — what to match
  3. sum range — values to add from the corresponding rows

In the category summary, D2 contains Stationery. Enter a SUMIF in F2 to add the Amount (USD) values for every source record whose Category matches D2.

Stationery sales total

In F2, enter this formula and format the result as US dollars with two decimal places.

excel
=SUMIF(A2:A10,D2,B2:B10)
Expected output
$250.00

The displayed result assumes F2 is formatted as US currency with two decimal places.

Tip

Comma or semicolon?

In Calc configurations that use semicolons, use:

=SUMIF(A2:A10;D2;B2:B10)

The accepted separator depends on your application and locale settings. The criterion D2 selects the Stationery source records in column A; SUMIF then adds the amounts from the matching rows in column B.

Keep the ranges aligned

Row pairing determines the total

Diagram showing that A2 pairs with B2, A5 with B5, A7 with B7, and A10 with B10; a shifted B3:B11 range pairs the category cells with wrong amount rows.

Correct ranges begin and end on the same source-record rows. A shifted range can contain the same number of cells but pair records incorrectly.

Equal size is not enough

SUMIF pairs positions row by row. With A2:A10 as the criteria range, the sum range must be B2:B10: row 2 is paired with row 2, through row 10 with row 10.

Do not judge alignment by range size alone. A2:A10 and B3:B11 both contain nine cells, but their first rows differ. That shift makes the Stationery test in A2 use the amount in B3, not B2.

A plausible but incorrect result

This shifted formula is structurally wrong, even though it returns a number.

excel
=SUMIF(A2:A10,D2,B3:B11)
Expected output
$350.00

The result is wrong because the amounts are shifted one row relative to the source categories. B11 is outside the source records and is blank.

Verify the source-record links

Check row-by-row pairing

Match each Stationery category cell to the amount cell from the same aligned source record.

Tap an item and then its matching pair.

Apply the aligned SUMIF

Repair the Stationery total

In F2, repair the shifted-range formula. Use the range diagram to keep every tested category cell paired with the amount from the same source-record row. The completed formula must summarize Stationery and return $250.00.

excel
=SUMIF(,D2,)

Step 4 of 8

Use Numeric Conditions

Count and total source-record amounts using literal numeric criteria, then compare inclusive and strict boundaries.

Read the boundary correctly

Test amounts, not categories

Numeric conditions test the Amount (USD) source records, so the criteria range is B2:B10.

A bare numeric criterion tests equality: 100 means exactly 100. A comparison criterion combines an operator and a number inside straight double quotation marks: ">=100" means 100 or more.

The inclusive operator >= includes an amount on the boundary. The strict operator > excludes an amount exactly equal to the boundary.

See the inclusive boundary

A threshold diagram showing four amount bars at or above 100, including one bar exactly on the threshold line.

An inclusive condition includes the amount that is exactly on its boundary.

Count and total qualifying amounts

Test equality, inclusive, and strict conditions

Use the temporary practice cells consistently: H4 checks equality, H5:H6 check the inclusive condition, and H7:H8 check the strict condition. Enter one separator version only. Use the comma formulas if your application accepts commas; otherwise use the semicolon formulas. Format H6 and H8 as US dollars with two decimal places. Display H4, H5, and H7 as whole numbers.

Excel / Calc formula
Comma separator:
H4: =COUNTIF(B2:B10,100)
H5: =COUNTIF(B2:B10,">=100")
H6: =SUMIF(B2:B10,">=100",B2:B10)
H7: =COUNTIF(B2:B10,">100")
H8: =SUMIF(B2:B10,">100",B2:B10)

Semicolon equivalent — use instead if required by your locale:
H4: =COUNTIF(B2:B10;100)
H5: =COUNTIF(B2:B10;">=100")
H6: =SUMIF(B2:B10;">=100";B2:B10)
H7: =COUNTIF(B2:B10;">100")
H8: =SUMIF(B2:B10;">100";B2:B10)
Expected output
H4: 1
H5: 4
H6: $570.00
H7: 3
H8: $470.00

The monetary results assume US-dollar formatting with two decimal places. H4, H5, and H7 are counts.

Tip

Test and add the same records

In each SUMIF formula, B2:B10 is both the criteria range and the sum range. Each source-record amount is tested; an amount that meets the condition is also added. Using the same range for both roles keeps the tested amounts and added amounts aligned.

Expected checks

Compare the two boundary conditions after entering the formulas.

The amount of $100.00 creates the difference between inclusive and strict conditions.
ConditionMatching recordsSales (USD)
>=1004$570.00
>1003$470.00
=1001$100.00

Check the strict boundary

Separate strict from inclusive

For the source records, which result belongs to the strict condition ">100"?

Complete and verify the formulas

Apply and verify both numeric boundaries

Complete the inclusive pair for amounts at least $100.00 and the strict pair for amounts greater than $100.00. Enter the completed formulas in H5:H8 on your Sales worksheet, using your application’s accepted separator, and verify the displayed count and total for each condition.

Excel formula
H5: =COUNTIF(B2:B10,"")
H6: =SUMIF(B2:B10,"",B2:B10)
H7: =COUNTIF(B2:B10,"")
H8: =SUMIF(B2:B10,"",B2:B10)

Step 5 of 8

Control the Condition from a Cell

Replace a hard-coded numeric comparison with a criterion built from an operator and the threshold in H2.

Construct a threshold-driven condition

Build a criterion from H2

Use H2 as the control for a numeric condition instead of typing the threshold inside each formula. Enter Threshold (USD) in H1 and enter 100 in H2.

The & operator joins pieces of a criterion. Keep the comparison operator in straight double quotation marks, but leave the cell reference outside them:

">="&H2

When H2 contains 100, this constructs the criterion >=100. If you later change H2, the formulas use the new threshold automatically.

How the referenced condition works

A threshold cell with 100 is joined to a greater-than-or-equal-to operator and used to select qualifying amounts in a spreadsheet column.

H2 supplies the changing number; the quoted operator and & create the criterion used by both functions.

Use H2 in both conditional formulas

Enter the first formula in H4 and the second in H5. Format H5 as US dollars with two decimal places.

The formulas below use commas. Calc installations or locales that use semicolons require the equivalent semicolon versions.

Excel / Calc formula
=COUNTIF(B2:B10,">="&H2)
=SUMIF(B2:B10,">="&H2,B2:B10)

=COUNTIF(B2:B10;">="&H2)
=SUMIF(B2:B10;">="&H2;B2:B10)
Expected output
H4: 4
H5: $570.00

The displayed results assume H2 contains 100. Formula separators depend on the application and locale settings.

See the formulas update

Example

Change the threshold, not the formulas

At a threshold of 100, the inclusive condition includes the amount exactly equal to 100. The qualifying amounts are 120, 200, 100, and 150, so H4 shows 4 and H5 shows $570.00.

Change only H2 to 150. The formulas do not need editing: H4 updates to 2, and H5 updates to $350.00. This happens because the criterion is rebuilt from the current value in H2.

After checking the update, restore H2 to 100 for the remaining practice.

Practice the formula pattern

Complete the referenced criterion

Complete both criteria so the formulas use an inclusive threshold from H2.

Excel / Calc formula
=COUNTIF(B2:B10,)
=SUMIF(B2:B10,,B2:B10)

Apply the controlled threshold

Control and verify both calculations

On the Sales worksheet, enter threshold-driven COUNTIF and SUMIF formulas in H4 and H5 using B2:B10 and H2. First check the results with H2 set to 100. Then change H2 to 150 and check both updated results. Finally, restore H2 to 100.

Report the two formulas you entered, the count and sales total at each threshold, and confirm that H2 is restored.

Write at least 100 characters (0/100).

Step 6 of 8

Copy a Reliable Category Summary

Anchor COUNTIF and SUMIF source ranges so a category summary can be copied down reliably.

Fix the source ranges before copying

Keep the data source fixed

Your category summary already has category labels in D2:D4. When you copy its formulas down, the source records must stay on the same nine rows. Only the criterion cell should move from D2 to D3, then D4.

Use absolute references for the source ranges and a relative reference for the category criterion.

What changes during a fill-down

The source ranges remain fixed; the category criterion advances one summary row at a time.

A diagram showing fixed source columns feeding several category-summary rows while the criterion reference advances down the summary.

The source ranges remain fixed; the category criterion advances one summary row at a time.

Enter once, then fill down

Enter the first summary row

On the Sales worksheet, enter the count formula in E2 and the total formula in F2. The dollar signs lock both source ranges. D2 has no dollar signs because it must change when you fill the formulas down through row 4.

Use the comma version below only if your application accepts commas. If your Excel or Calc locale uses semicolons, use the semicolon version instead. Do not enter both versions or mix separators in one formula.

Anchored formulas for row 2

Enter one matching separator version in E2 and F2. Check the displayed results before filling down.

excel
Comma separator:
E2: =COUNTIF($A$2:$A$10,D2)
F2: =SUMIF($A$2:$A$10,D2,$B$2:$B$10)

Semicolon separator:
E2: =COUNTIF($A$2:$A$10;D2)
F2: =SUMIF($A$2:$A$10;D2;$B$2:$B$10)
Expected output
E2: 4
F2: $250.00

Use only the comma formulas or only the semicolon formulas, according to your application and locale settings. F2 must be formatted as US dollars with two decimal places.

Example

Inspect a copied formula

Fill E2:F2 down through row 4. Then select F3 and inspect its formula in the formula bar. The criteria range and sum range should still begin at row 2 and end at row 10, while the criterion should now refer to the category in row 3.

If a source reference changed row, undo the fill, correct the missing dollar signs in row 2, and fill down again.

Practice the anchoring pattern

Lock both SUMIF source ranges

Complete the formula so its two source ranges remain fixed when copied down the category summary.

excel
=SUMIF(,D2,)

Apply the complete copy-down

Build and inspect the copied category summary

Complete the category summary on your own worksheet:

  1. In E2, use COUNTIF with an anchored category criteria range and D2 as the relative criterion.
  2. In F2, use SUMIF with anchored category criteria and sum ranges and D2 as the relative criterion.
  3. Fill E2:F2 down through row 4.
  4. Format E2:E4 as whole numbers and F2:F4 as US dollars with two decimal places.
  5. Inspect F3 in the formula bar.

Report the three category results in E2:F4 and the formula displayed in F3.

Write at least 80 characters (0/80).

Step 7 of 8

Test Missing Matches and Filtered Rows

Test zero-result cases and confirm that conditional formulas still evaluate all referenced source records when a worksheet filter hides some rows.

What a zero can—and cannot—tell you

Interpret a zero result

A $0.00 total can mean two different things. If the category is absent, both the matching-record count and the total are zero. If matching records exist but their amounts add to zero, the total is still $0.00, but the count is not zero.

Keep the source records unchanged. Use a count alongside a total whenever you need to tell these cases apart.

Diagram comparing an absent category with a matching record whose amount is zero.

An absent category produces count 0 and total $0.00. The amount condition 0 finds one source record, yet its total is also $0.00.

Example

Test absence and a zero amount

Use H4:H7 for these temporary checks:

  • In H4: =COUNTIF(A2:A10,"Services") → 0

Calc separator variant: =COUNTIF(A2:A10;"Services")

  • In H5: =SUMIF(A2:A10,"Services",B2:B10) → $0.00

Calc separator variant: =SUMIF(A2:A10;"Services";B2:B10)

  • In H6: =COUNTIF(B2:B10,0) → 1

Calc separator variant: =COUNTIF(B2:B10;0)

  • In H7: =SUMIF(B2:B10,0,B2:B10) → $0.00

Calc separator variant: =SUMIF(B2:B10;0;B2:B10)

Whether your application accepts commas or semicolons depends on its locale settings. Format total cells as US dollars with two decimal places and count cells as whole numbers.

Practice: test an absent category

Build the no-match count

Complete the criterion for the absent-category check.

Excel formula
=COUNTIF(A2:A10,"")

Check formulas while rows are filtered

Put filter checks below the source

A worksheet filter changes which source rows you can see; it does not change the cells referenced by COUNTIF or SUMIF. To test this clearly, place the outputs outside the filtered range.

In H12 enter:
=COUNTIF(A2:A10,"Accessories")
Calc variant: =COUNTIF(A2:A10;"Accessories")

In H13 enter:
=SUMIF(A2:A10,"Accessories",B2:B10)
Calc variant: =SUMIF(A2:A10;"Accessories";B2:B10)

H12 should display 3 and H13 should display $200.00. Format H13 as US dollars with two decimal places.

A filtered source table with formula outputs below it still visible and connected to the full source range.

Filter A1:B10 to show Stationery only. The checks in H12:H13 remain visible and keep their Accessories results because their formulas still evaluate A2:A10 and B2:B10.

Tip

Filter visibility is not formula scope

After entering the checks, filter A1:B10 so that only Stationery source records are visible. Do not use the visible rows as the basis for a new calculation: inspect H12 and H13 instead. Their values do not change. Clear the filter when the check is complete so the full source is ready for the final audit.

Run the verification sequence

Verify missing matches and filtered rows

Perform one complete verification on your worksheet:

  1. Use the temporary checks in H4:H7 to verify the absent-category case and the zero-amount case.
  2. Put the Accessories COUNTIF check in H12 and the Accessories SUMIF check in H13.
  3. Filter A1:B10 to show only Stationery, then inspect the two outputs below the source records.
  4. Clear the filter.

In your response, report the count and total for Services, the count and total for the amount condition 0, and the count and total shown by the filtered Accessories checks. Also confirm that you cleared the filter.

Write at least 100 characters (0/100).

Step 8 of 8

Reconcile and Verify the Summary

Complete a final audit of the category summary by reconciling counts and amounts with the source records.

Set up the final audit

Audit the complete summary

A reliable category summary accounts for every source record once. In Sales, the three category rows in D2:D4—Stationery, Accessories, and Storage—are the complete set of source categories. D5 is a grand-total row, not another category.

Before the final audit, clear any worksheet filter. Then inspect the category formulas: each criteria range should cover A2:A10, each sum range should cover B2:B10, and each criterion should point to its category cell in column D. Formula inspection can catch an incorrect range even when a grand total looks plausible.

From source records to one reconciled summary

Diagram showing nine source records grouped into three categories, then combined into count and amount totals.

Each source record belongs to one category row, so the complete category summary can be checked against the full source.

Audit checkpoints

Use these independent checkpoints after calculating the category summary. A known-match check confirms an individual category result; the Services test confirms that an absent criterion produces zeros.

Expected results from the nine source records
CheckExpected countExpected amount
All source records9$800.00
Stationery known match4$250.00
Services no-match0$0.00

Add the All categories row

Create independent grand-total checks

Complete the All categories row by adding the already calculated category-summary results—not by adding another conditional criterion.

Enter the count formula in E5 and the sales formula in F5. Independently check the amount by summing the source amount range. SUM has one range argument, so it is written the same way in Excel and Calc regardless of the separator used for multi-argument functions.

Format F5 as US dollars with two decimal places and keep E5 as a whole number.

Grand-total formulas

Enter these formulas in the indicated cells.

excel
E5: =SUM(E2:E4)
F5: =SUM(F2:F4)

Independent source-amount check:
=SUM(B2:B10)
Expected output
9
$800.00
$800.00

Displayed results, in the same order as the three entries: E5, F5, then the independent source-amount check.

Warning

Do not rely on one total alone

Grand-total agreement is necessary, but it is not sufficient. A shifted criteria range or sum range can sometimes produce a believable total. Keep individual category checks, the Services no-match check, and formula inspection as part of the audit.

Apply the reconciliation formulas

Complete the All categories formulas

Fill the two range references so the All categories row totals the category summary.

excel
E5: =SUM()
F5: =SUM()

Verify and finish

Final verification report

With the worksheet filter cleared, finish the audit in Sales. In 2–4 sentences, report:

  • the values in E5 and F5 after completing the All categories row;
  • whether F5 agrees with =SUM(B2:B10), including the dollar result;
  • one known-match check with its category, count, and sales total;
  • the COUNTIF and SUMIF results for Services; and
  • why filtering or hiding source rows is not a valid way to restrict these formulas.

Write at least 180 characters (0/180).

Tutorial complete

Congratulations! You completed: Summarize Matching Records with SUMIF and COUNTIF

You reconciled the category summary with the source records, tested matching and missing criteria, and verified that filters do not limit conditional formulas.

Download the App now to have access to + 5000 free courses, exercises, certificates and lots of content without paying anything!

  • 100% free online courses from start to finish

    Thousands of online courses in video, ebooks and audiobooks.

  • More than 60 thousand free exercises

    To test your knowledge during online courses

  • Valid free Digital Certificate with QR Code

    Generated directly from your cell phone's photo gallery and sent to your email

Cursa app on the ebook screen, the video course screen and the course exercises screen, plus the course completion certificate