Subtotal One Column and Count Another Column


October 05, 2022 - by

Subtotal One Column and Count Another Column

Problem: I want to subtotal revenue and count the number of records. The Subtotal dialog offers 11 different summary functions including two counting functions. How do I change the function for different columns? I’ve tried adding the SUM to Revenue, then doing subtotals a second time to count the customer, but the subtotals end up on two different rows.

Strategy: When you add subtotals, Excel makes use of a function called =SUBTOTAL(). The first argument of the SUBTOTAL function tells Excel which summary function to use.


=SUBTOTAL(9, is the argument for sum. There are 11 functions to choose from. Microsoft arranged the arguments alphabetically.

Type =SUBTOTAL( and the tooltip for Function Number will show the list as 
1 Average
2 Count
3 CountA
4 Max
5 Min
6 Product
7 StDev.S
8 StDev.P
9 Sum
10 Var.S
11 Var.P
Those names are the alphabetical sequence of the 11 functions in English.
Figure 734. SUM is 9th.

The solution is to add automatic subtotals to the numeric columns and the text column that you want to count. Of course, the totals on the text column will be zero.

Including Region as one of the columns to Subtotal leads to a bunch of 0 answers, since East+West+Central is zero. But: notice the formula bar in the Region column: =SUBTOTAL(9,A77:A80). The goal is to change the function numer from 9 to 3 for COUNTA.
Figure 735. Total a text column.


  • 1. Select the entire text column.

  • 2. Use Ctrl+H to display the Find and Replace dialog.

  • 3. Type (9, in the Find What box.

  • 4. Type (3, in the Replace With box.

  • 5. Press Replace All.

In the Find & Replace dialog, choose Replace. Find What: (9, Replace With: (3, and then click Replace All
Figure 736. Change the 9 argument to 3.

This will change the SUBTOTAL function from one that sums to one that counts text entries. You will have a count in column A and a sum in column E.

The formula in the Region column now shows 28, meaning that there are 28 rows in this section.
Figure 737. Counts and sums on the same row.

This article is an excerpt from Power Excel With MrExcel

Title photo by ANIRUDH on Unsplash