To define a subtotal in Excel, you can either use the built-in Subtotal tool found in the Data tab or manually enter the SUBTOTAL function into a cell. The Subtotal tool automatically groups your data and inserts totals for specific categories, while the SUBTOTAL function allows you to perform calculations (like sum, average, or count) that ignore other subtotal formulas or hidden rows in a filtered list. This is essential for managing large datasets where you need quick summaries without manually adding every cell.
What You'll Need
- A computer with Microsoft Excel installed.
- A dataset organized in a table or range with clear column headers.
- Data that is sorted by the category you wish to group (if using the automatic Subtotal tool).
Step-by-Step
Method 1: Using the Automatic Subtotal Tool
The automatic tool is the fastest way to insert totals into a list of data. Note that menu labels may differ slightly depending on your version of Excel or region.
- Sort Your Data: This is the most critical step. Select the column you want to group by (e.g., "Region" or "Department"). Go to the Data tab and click Sort A to Z or Sort Z to A. If you skip this, Excel will create a new subtotal every time the value in that column changes, resulting in a fragmented and useless list.
- Select the Range: Click any single cell within your data range. Excel will automatically detect the boundaries of your data table.
- Open the Subtotal Dialog: Navigate to the Data tab. In the Outline group (usually on the far right), click the Subtotal button.
- Configure the Settings: A dialog box will appear. Fill in the following:
- At each change in: Select the column you just sorted (e.g., "Region").
- Use function: Choose the calculation you need, such as Sum, Count, or Average.
- Add subtotal to: Check the boxes for the columns containing the numerical values you want to calculate.
- Apply the Subtotals: Click OK. Excel will now insert new rows containing the subtotals and create an outline on the left side of the worksheet.
- Manage the View: Use the small numbers (1, 2, 3) in the top-left corner of the spreadsheet to collapse or expand the data. Level 1 shows the Grand Total, Level 2 shows the Subtotals, and Level 3 shows all individual records.
Method 2: Using the SUBTOTAL Function Manually
If you prefer more control or are working with filtered lists, use the formula approach. The syntax is =SUBTOTAL(function_num, ref1, [ref2], ...).
- Select the Target Cell: Click the cell where you want the total to appear (usually at the bottom of a column).
- Enter the Function: Type
=SUBTOTAL(into the cell. - Choose the Function Number: The first argument is a number that tells Excel which calculation to perform. Common numbers include:
- 9 for SUM (includes hidden rows).
- 109 for SUM (ignores manually hidden rows).
- 1 for AVERAGE (includes hidden rows).
- 101 for AVERAGE (ignores manually hidden rows).
- 2 for COUNT (includes hidden rows).
- 102 for COUNT (ignores manually hidden rows).
- Define the Range: After the comma, select the range of cells you want to calculate (e.g.,
B2:B50). - Close and Execute: Type the closing parenthesis
)and press Enter.
Common Mistakes
One of the most frequent errors is forgetting to sort the data before using the automatic Subtotal tool. If your data is unsorted, Excel treats every change in the category as a new group. For example, if your "Region" column goes "North, South, North, East," Excel will create three separate subtotals instead of grouping the two "North" entries together.
Another common mistake is applying the Subtotal tool to data that is already formatted as an official Excel Table (created via Ctrl+T). The Subtotal tool is greyed out for official Tables because Tables have their own "Total Row" feature. To use the Subtotal tool, you must first convert the Table back to a normal range by going to Table Design > Tools > Convert to Range.
Users also often confuse the SUM function with the SUBTOTAL function. If you use SUM at the bottom of a list that already contains other SUM formulas for categories, you will double-count the values. The SUBTOTAL function is designed specifically to ignore other SUBTOTAL formulas within the range, preventing this mathematical error.
Tips
To quickly remove all automatically generated subtotals, go back to the Data tab, click Subtotal, and then click the Remove All button in the bottom-left of the dialog box. This returns your data to its original flat state without deleting your actual data.
If you are working with a very large dataset, use the 100-series function numbers (like 109 instead of 9). While the 1-11 series ignores rows hidden by a filter, the 101-111 series ignores both filtered rows and rows you have manually hidden by right-clicking the row header and selecting "Hide." This provides much tighter control over what is being calculated in your report.
Combine subtotals with the "Group" feature for a professional look. If you are manually creating subtotals, you can select the detail rows and go to Data > Group to create a collapsible section, mimicking the behavior of the automatic tool.
Troubleshooting
The Subtotal button is greyed out: This usually happens because your data is formatted as a Table. Select any cell in the table, go to the Table Design tab, and select Convert to Range. Once the data is a standard range, the Subtotal button will become active.
The total is incorrect or double-counting: Check if you used =SUM() instead of =SUBTOTAL(). If you have nested totals, the SUM function adds everything in the range regardless of whether it is a subtotal or a raw value. Replace these with =SUBTOTAL(9, range) to ensure only raw data is summed.
The subtotals are appearing in random places: This is a sorting issue. Undo your changes, select your grouping column, sort it alphabetically or numerically, and then apply the Subtotal tool again. The tool only creates a subtotal when the value in the specified column changes.
The formula returns a #VALUE! error: Ensure that the range you selected contains only numbers. If there are text strings or errors (like #DIV/0!) within the range, the SUBTOTAL function may fail. Use the Find and Replace tool to clear out non-numeric data from your value columns.
Frequently Asked Questions
What is the difference between SUM and SUBTOTAL?
The SUM function adds all numbers in a range. The SUBTOTAL function can perform various calculations and, crucially, ignores other SUBTOTAL formulas in the same range, preventing double-counting. It also has the ability to ignore hidden rows.
Can I use SUBTOTAL with a Pivot Table?
No, you do not need the SUBTOTAL function for Pivot Tables. Pivot Tables have built-in aggregation settings that automatically provide subtotals and grand totals for every field added to the Rows or Columns area.
Why does the SUBTOTAL function ignore filtered rows?
This is a core feature designed for dynamic reporting. When you apply a filter to a dataset, the SUBTOTAL function updates its result to reflect only the visible data, making it ideal for dashboards.
Which function number should I use for a count?
Use 2 to count cells containing numbers, including manually hidden rows. Use 102 to count cells containing numbers while ignoring manually hidden rows. Both ignore rows hidden by a filter.
Can I have multiple levels of subtotals?
Yes. After applying the first set of subtotals, you can click the Subtotal button again. In the dialog box, uncheck the box that says "Replace current subtotals." This allows you to add a second layer of grouping (e.g., subtotals by City, then subtotals by State).