How to Use Excel Subtotal Formula
In this article
You can use the SUBTOTAL function in Excel to calculate sums, averages, counts, and more within a filtered list without messing up your existing formulas. To start, ensure your data is organized in columns, with headers in the first row, and that you have no blank rows separating your data groups, as the function relies on contiguous ranges. The SUBTOTAL function is designed to ignore other SUBTOTAL functions within the same range, which makes it perfect for nested calculations, and it automatically adjusts its behavior when you apply Excel filters to the data.
What You'll Need
- A computer with Microsoft Excel installed (Excel 2013 or newer is recommended for the best experience).
- A dataset with numerical data organized in rows and columns.
- A computer mouse or trackpad for selecting cells and navigating menus.
Step-by-Step
- Organize Your Data – Begin by entering your data into a worksheet. It is crucial that your data is a continuous block. For example, if you have sales data for different regions, ensure that every cell in that column is filled; do not leave blank rows between regions. The first row should contain headers like "Product," "Region," and "Sales Amount." This structure is essential for Excel to correctly interpret the range.
- Select the Cell for the Result – Click on the empty cell where you want the subtotal to appear. This could be at the bottom of your data column or in a summary area. It is often helpful to place this cell just below the last row of your data to keep the summary visible while scrolling.
- Open the Formula Menu – Click on the "Formulas" tab located in the Excel ribbon at the top of the window. In the "Function Library" group, you will see a button labeled "Insert Function." Click this button. Alternatively, you can type the function name manually by typing "=" followed by "SUBTOTAL(". The Insert Function dialog box will appear, listing all available functions.
- Choose the Function Number – In the "Select a function" list, you will see that the SUBTOTAL function has two sets of numbers. The first set (1-11) includes functions that ignore hidden rows, while the second set (101-111) includes functions that include hidden rows. For most standard subtotaling tasks, you will use the first set. For example:
- 1 corresponds to SUM.
- 2 corresponds to AVERAGE.
- 3 corresponds to COUNT.
- 9 corresponds to SUM (the most common choice).
- Select Your Range – The dialog box will ask for a "Number1" argument. Click the small arrow icon next to the input box to collapse the dialog window. This allows you to see your spreadsheet. Click and drag your mouse over the column of data you want to subtotal. You will see the range appear in the input box (e.g., B2:B100). If you also want to include another column in the calculation (like a category column for grouping), you can type a comma and select that range as well (e.g., "A2:A100").
- Confirm the Formula – Click the small arrow icon again to expand the dialog window. Click the "OK" button. The result will appear in your selected cell. Excel will display the total sum of the numbers in that range.
- Apply a Filter (Optional but Recommended) – To see the true power of the SUBTOTAL function, apply a filter to your data. Click on any cell within your header row. Go to the "Data" tab in the ribbon and click the "Filter" button (it looks like a funnel). Dropdown arrows will appear next to your headers. Click the arrow next to the category header you want to filter by (e.g., "Region"). Uncheck "Select All" and then check only the regions you want to see. Click OK.
- Verify the Result – Look at the subtotal cell you created earlier. The number should automatically update to reflect only the visible rows. This demonstrates that the SUBTOTAL function respects the filter settings. You can now toggle different regions on and off, and the subtotal will change instantly.
- Create Multiple Subtotals (Advanced) – To get more granular, you can insert a subtotal at the bottom of each group. Place your cursor anywhere within your data. Go to the "Data" tab and click the "Subtotal" button. In the dialog box, select the column you want to group by (e.g., "Region") from the "At each change in" dropdown menu. Choose the function you want to use (e.g., "Sum") from the "Use function" dropdown. Ensure that the check box for "Add subtotal to" is checked for the column you want to calculate (e.g., "Sales Amount"). Click OK. Excel will insert a new row below each region with the subtotal and a grand total at the very bottom of the list.
Common Mistakes
One of the most common mistakes when using the SUBTOTAL function is using the wrong function number. Beginners often try to use the standard SUM function directly, which does not respect Excel filters. If you filter your data and use a regular SUM function, Excel will sum all the numbers, including those hidden by the filter, leading to incorrect totals. Always ensure you are using the SUBTOTAL function specifically, and select the correct number corresponding to the standard function you intend to use (e.g., 9 for SUM).
Another frequent error is not having a continuous range of data. The SUBTOTAL function requires that the cells it is analyzing are adjacent to each other. If you have blank rows between your data, the function will stop calculating at the first blank row, resulting in a partial subtotal. You must ensure that your data is clean and contiguous before applying the function.
Tips
Use the function numbers 1-11 when you want your subtotals to ignore hidden rows. This is the standard behavior for most reports. If you are creating a summary table where you manually hide rows to focus on specific sections, and you want those hidden rows to be included in the calculation, use the function numbers 101-111. However, be aware that this behavior is the exact opposite of standard Excel filtering behavior, which can be confusing if you are mixing filtered data with manually hidden rows.
When you use the SUBTOTAL function, it will automatically ignore other SUBTOTAL functions within the same range. This is a critical feature for nested calculations. For example, if you have a subtotal for each region and then a grand total at the bottom, the grand total will only sum the region subtotals, not the raw data. This prevents double-counting and ensures your final numbers are accurate.
Troubleshooting
If your SUBTOTAL formula is returning a #VALUE! error, it is often because your range includes non-numeric data. The SUBTOTAL function is designed to work with numbers, and if it encounters text or blank cells in the range, it will throw an error. Check your data to ensure that all cells in the selected range contain either numbers or formulas that result in numbers. You can use Excel's "Go To Special" feature to find non-numeric cells by pressing Ctrl+G, clicking "Special," and selecting "Constants" to identify the problematic cells.
If your subtotal is not updating when you apply a filter, it is likely because you used a regular SUM function instead of a SUBTOTAL function, or you used a SUBTOTAL function with the wrong function number. Check your formula to ensure it starts with "=SUBTOTAL(" and that the function number is 1-11. If you are still having trouble, try restarting Excel. Sometimes, the application can get stuck in a state where it is not refreshing the formulas correctly. If this does not work, check your Excel version and ensure you are running the latest updates.
If your subtotal is not calculating correctly because it is including hidden rows, you need to change the function number. If you are using function numbers 1-11, switch to 101-111. If you are using function numbers 101-111, switch to 1-11. It is important to understand that these numbers are not related to the order of the alphabet or any other logic; they are simply hard-coded identifiers for the specific function behavior.
Frequently Asked Questions
What is the difference between SUBTOTAL and SUM?
The main difference is how they react to filters. SUM adds all numbers in a range, regardless of visibility. SUBTOTAL only adds numbers in visible rows, making it essential for analyzing filtered data. Additionally, SUBTOTAL can perform other calculations like AVERAGE and COUNT, while SUM is strictly for addition.
Can I use SUBTOTAL with 3D references?
No, the SUBTOTAL function does not support 3D references. 3D references are used to reference the same cell or range on multiple sheets (e.g., Sheet1!A1, Sheet2!A1). If you try to use a 3D reference with SUBTOTAL, it will result in a #VALUE! error. You must use standard 2D references for the function to work.
Why does my SUBTOTAL formula show "#DIV/0!"?
This error occurs when you are using the AVERAGE function (function number 2) and all the numbers in the range are zero or blank. A dividing by zero is mathematically impossible, so Excel cannot calculate the average. Ensure you have at least one non-zero number in the range before using the AVERAGE function.
Does SUBTOTAL work with pivot tables?
Yes, pivot tables automatically use a variation of the SUBTOTAL function to calculate values. This allows the pivot table to show different summaries for different levels of detail. You can modify these calculations in the pivot table settings if needed, but the underlying mechanism relies on the SUBTOTAL logic.
How do I subtotal multiple columns at once?
You can subtotal multiple columns by selecting all the columns you want to calculate before inserting the subtotal. Alternatively, you can insert one subtotal and then drag the fill handle across the other columns to copy the formula to adjacent cells. This is a quick way to get summary statistics for a whole group of columns.