To perform a subtotal with SUMIF logic in Excel, you cannot use the standard SUMIF function because it includes hidden rows in its calculation. Instead, you must use a combination of the SUMPRODUCT function and the SUBTOTAL function (specifically function number 103 or 3) to create a "visibility check" for each row. This allows you to sum values based on specific criteria while ignoring any rows that have been hidden by a filter.

What You'll Need

  • Microsoft Excel (Desktop version recommended for full formula support).
  • A dataset organized in a table or a range with clear column headers.
  • At least one column containing the criteria you want to filter by (e.g., Category, Region, or Status).
  • A column containing the numerical values you wish to sum.

Step-by-Step

  1. Prepare Your Data Range: Ensure your data is in a continuous block without completely empty rows or columns. For the best results, convert your data range into an official Excel Table by selecting your data and pressing Ctrl + T. This ensures that as you add new rows, your formulas can be updated more easily using structured references.
  2. Identify Your Criteria and Sum Range: Determine which column contains the category you want to sum (the Criteria Range) and which column contains the numbers (the Sum Range). For this example, assume Column A contains "Category" and Column B contains "Amount".
  3. Create a Helper Column (The Simplest Method): While a complex single formula exists, the most reliable way to achieve a "SUMIF Subtotal" is by adding a helper column that identifies if a row is visible. In a new column (e.g., Column C), enter the formula =SUBTOTAL(103, A2) and drag it down to the bottom of your dataset. The number 103 tells Excel to count the cell only if it is visible; it returns 1 if the row is shown and 0 if it is hidden by a filter.
  4. Apply the SUMIFS Formula with the Helper: Now, instead of a standard SUMIF, use SUMIFS to include the helper column as an additional criterion. Use the following formula structure: =SUMIFS(Sum_Range, Criteria_Range, "Your_Criteria", Helper_Column, 1). For example: =SUMIFS(B2:B100, A2:A100, "Electronics", C2:C100, 1). This tells Excel to sum the amounts where the category is "Electronics" AND the row is currently visible.
  5. Alternative: The Advanced Single-Cell Formula: If you cannot add a helper column, you can use a SUMPRODUCT array. Enter this formula: =SUMPRODUCT((A2:A100="Electronics") * (SUBTOTAL(103, OFFSET(A2, ROW(A2:A100)-MIN(ROW(A2:A100)), 0))) * (B2:B100)). Here is how this works: the first part checks for your criteria; the second part uses OFFSET and SUBTOTAL to create an array of 1s and 0s based on visibility; the third part provides the values to sum.
  6. Test the Filter: Apply a filter to your data using the Filter button in the Data tab. Select and deselect items in your filter dropdown. You will notice that the standard SUMIF total remains the same regardless of the filter, but your new Subtotal-SUMIF formula updates in real-time to reflect only the visible rows that meet your criteria.

Common Mistakes

One of the most frequent errors is using the standard =SUMIF() or =SUMIFS() and expecting the total to change when rows are filtered. These functions are designed to look at the entire range specified, regardless of whether the row is hidden by a filter or manually hidden. They do not "see" the filter state of the worksheet.

Another common mistake is using the wrong function number within the SUBTOTAL function. Using 3 instead of 103 can lead to discrepancies. Function 3 counts hidden rows that were hidden manually (Right-click > Hide), whereas 103 ignores both manually hidden rows and rows hidden by an AutoFilter. If you want your total to be truly dynamic based on all forms of hiding, always use the 100-series codes.

Users also often forget to lock their ranges. If you are dragging your subtotal formula across multiple cells to create a summary table, failure to use absolute references (e.g., $A$2:$A$100) will cause the range to shift, leading to incorrect totals or #VALUE! errors.

Tips

To make your summary more dynamic, instead of typing the criteria (like "Electronics") directly into the formula, reference a cell. For example, use =SUMIFS(B2:B100, A2:A100, E1, C2:C100, 1) where cell E1 contains the name of the category. This allows you to change the category you are tracking without editing the formula itself.

If you are dealing with very large datasets (tens of thousands of rows), the SUMPRODUCT/OFFSET method can slow down your workbook because it is a volatile calculation. In these cases, the helper column method is significantly more performant because the SUBTOTAL calculation is handled row-by-row and the SUMIFS function is highly optimized for speed.

Consider using a Pivot Table as an alternative. While the SUMIF/SUBTOTAL combination is great for custom dashboards, a Pivot Table allows you to filter and sum categories instantly without writing complex formulas. You can simply drag the Category to the Rows area and the Amount to the Values area, then use a Slicer to filter the data.

Troubleshooting

If your formula returns 0 when you know there should be a value, first check for data type mismatches. Ensure that your sum range contains actual numbers and not "numbers stored as text." You can identify this by looking for small green triangles in the corners of the cells. Select the cells and use the warning icon to "Convert to Number."

If you receive a #VALUE! error, check that all ranges in your SUMIFS or SUMPRODUCT formula are the exact same size. If your criteria range is A2:A100 but your sum range is B2:B101, Excel cannot align the rows and will return an error.

If the total does not change when you filter, double-check your helper column. Ensure you used SUBTOTAL(103, ...) and not COUNT() or SUM(). The helper column must be a formula that evaluates each row individually; if you accidentally put a single total at the bottom of the helper column instead of a formula in every row, the SUMIFS will not function correctly.

Frequently Asked Questions

Can I use this with multiple criteria?

Yes. By using the SUMIFS function (with an 'S'), you can add as many criteria ranges as needed. Just ensure that the helper column (the visibility check) is always included as the final criteria pair.

Does this work in Google Sheets?

The logic is similar, but Google Sheets handles array formulas differently. You would typically use a combination of SUMPRODUCT, MAP, or BYROW along with SUBTOTAL to achieve the same result.

Why not just use the SUBTOTAL function alone?

The SUBTOTAL function can sum everything that is visible, but it cannot filter by a specific category (like "Electronics") within that visible set. It is an "all or nothing" sum for the visible rows. To get a specific category sum from a filtered list, you need the SUMIF logic.

Will this work if I manually hide rows?

Yes, provided you use the function number 103 in the SUBTOTAL formula. Function 103 ignores both filtered-out rows and rows that were hidden via the right-click menu.

Can I use this in an Excel Table?

Absolutely. Using an Excel Table (Ctrl+T) is actually recommended because you can use structured references (like [Amount]) instead of cell coordinates, making the formula much easier to read and maintain.