The SUBTOTAL function in Excel is used to perform a calculation (such as summing, averaging, or counting) on a range of cells while ignoring rows that have been hidden by a filter. Unlike the standard SUM or AVERAGE functions, which calculate every cell in a range regardless of whether it is visible, SUBTOTAL dynamically updates its result to reflect only the data currently displayed on your screen. This makes it the essential tool for creating reports with filterable tables where the totals must change as you narrow down your data set.

What You'll Need

  • Microsoft Excel (any modern version).
  • A data set organized in a table or a range with clear column headers.
  • Basic familiarity with applying filters to your data.

Step-by-Step

  1. Prepare Your Data: Ensure your data is organized in a clean list. For example, if you are tracking sales, you should have columns for "Date," "Region," "Salesperson," and "Amount." Make sure there are no completely empty rows or columns within the data block, as this can interfere with how Excel recognizes the range.
  2. Apply Filters: Select your header row. Navigate to the Data tab on the ribbon and click the Filter button. You will now see drop-down arrows on each header cell. This is crucial because the SUBTOTAL function's primary purpose is to interact with these filters.
  3. Select the Total Cell: Click on the cell where you want the result to appear. Usually, this is placed either directly above the data headers or at the very bottom of the column you are calculating.
  4. Enter the Function Syntax: Type =SUBTOTAL( into the cell. The function requires two arguments: a function_num (which tells Excel what kind of math to do) and a ref1 (the range of cells to calculate).
  5. Choose Your Function Number: Inside the parentheses, enter the number corresponding to the calculation you want. For example, enter 9 for a SUM or 1 for an AVERAGE. The syntax now looks like =SUBTOTAL(9, .
  6. Define the Range: While the cursor is still inside the formula, click and drag to select the range of cells you want to calculate (e.g., B2:B100). Close the parentheses and press Enter. The final formula should look something like =SUBTOTAL(9, B2:B100).
  7. Test the Filter: Use the filter drop-down arrows in your header row to filter your data. For instance, if you filter by "Region" to show only "North," you will notice that the SUBTOTAL result immediately changes to show the sum of only the visible "North" rows.

Common Mistakes

One of the most frequent errors is using the SUBTOTAL function on a range that includes the cell where the formula itself is located. This creates a circular reference, which causes Excel to display an error message and return a result of zero. Always ensure your range (e.g., B2:B100) does not include the cell where you wrote the formula (e.g., B101).

Another common mistake is confusing the function numbers. Users often assume that the numbers are arbitrary, but they are specific codes. Entering a number outside the 1-11 or 101-111 range will result in a #VALUE! error. Additionally, some users try to use SUBTOTAL to calculate data that has been hidden manually (by right-clicking a row and selecting "Hide") rather than using a filter. While SUBTOTAL can do this, it requires using the 100-series function numbers (e.g., 109 instead of 9).

Finally, users often apply SUBTOTAL to a range that is not actually a contiguous block of data. If there are gaps or if the range is selected inconsistently, the formula may miss data points, leading to inaccurate totals. Always double-check that your range selection covers every possible row that could be filtered into view.

Tips

Use the 100-series for Manual Hiding: If you manually hide rows by right-clicking the row header and selecting "Hide," the standard function numbers (1-11) will still include those hidden cells in the total. To ignore manually hidden rows, use the corresponding number plus 100. For example, use 109 instead of 9 for a sum. This ensures that if you hide a row for aesthetic reasons, it won't skew your totals.

Combine with Excel Tables: Convert your data range into an official Excel Table by pressing Ctrl + T. Once it is a table, you can enable the "Total Row" in the Table Design tab. Excel will automatically insert SUBTOTAL formulas into the bottom row, allowing you to switch between Sum, Average, and Count using a simple drop-down menu without typing the formulas manually.

Avoid Double Counting: If you have a large sheet with multiple sub-totals throughout the column, a final grand total using the standard SUM function will add the sub-totals and the individual items together, doubling your actual total. However, the SUBTOTAL function is designed to ignore other SUBTOTAL formulas within its range. If you use SUBTOTAL for your category totals and a SUBTOTAL for your grand total, Excel will only count the individual data points, preventing double-counting.

Troubleshooting

If your SUBTOTAL formula is returning 0 or an incorrect value, first check for Circular References. Look at the bottom left of the Excel window; if it says "Circular References" followed by a cell address, your formula is trying to calculate itself. Move the formula to a cell outside the range.

If the total does not change when you filter the data, verify that you are using a Filter from the Data tab and not just manually hiding rows. If you are manually hiding rows, remember to change your function number from 9 to 109 (or 1 to 101, etc.).

If you see a #VALUE! error, check the function number. Ensure it is a whole number between 1 and 11 or 101 and 111. Also, ensure that the range you selected contains only numbers. If the range includes text cells that cannot be converted to numbers, some function types may struggle, although the SUM (9) function typically ignores text.

If the formula is not updating automatically, check your Calculation Options. Go to the Formulas tab, click Calculation Options, and ensure it is set to "Automatic." If it is set to "Manual," the SUBTOTAL will not update until you press F9.

Frequently Asked Questions

What is the difference between SUM and SUBTOTAL?

SUM adds every cell in a range regardless of whether the row is hidden or filtered. SUBTOTAL only adds the cells that are visible after a filter has been applied, making it dynamic for reporting.

Which number should I use for a count of items?

Use function number 2 (COUNT) to count cells containing numbers, or function number 3 (COUNTA) to count any cell that is not empty, including those containing text.

Can I use SUBTOTAL for averages?

Yes, use function number 1 for the average of visible cells. If you are manually hiding rows and want those ignored, use function number 101.

Does SUBTOTAL work with Pivot Tables?

While you can use it, SUBTOTAL is generally unnecessary in Pivot Tables because Pivot Tables have built-in aggregation settings (Sum, Count, Average) that automatically update based on the filters and slicers you apply to the Pivot Table.

Why does my SUBTOTAL include rows I hid by right-clicking?

The function numbers 1-11 only ignore rows hidden by a filter. To ignore rows hidden manually via the right-click menu, you must use the 100-series numbers (101-111).

Can I nest SUBTOTAL formulas inside each other?

You can have multiple SUBTOTAL formulas in one column. The unique advantage is that a "Grand Total" SUBTOTAL formula at the bottom will ignore any other SUBTOTAL formulas located above it within the same range, preventing the total from being doubled.