Excel does not have a built-in "SUBTOTALIF" function, but you can achieve the same result by combining the SUMPRODUCT function with the SUBTOTAL function. This approach allows you to sum values based on specific criteria while ignoring rows that have been hidden by a filter. Standard SUMIF or SUMIFS formulas will include hidden rows in their total, which is why this advanced combination is necessary for dynamic dashboards and filtered reports.

What You'll Need

  • Microsoft Excel (Desktop version recommended for full functionality).
  • A dataset containing at least one column of categories (criteria) and one column of numeric values.
  • The dataset should ideally be formatted as an Excel Table (Ctrl + T) to make range references easier to manage.

Step-by-Step

  1. Prepare Your Data: Ensure your data is organized in columns with clear headers. For example, Column A could be "Department" and Column B could be "Sales Amount".
  2. Apply a Filter: Select your header row, go to the Data tab, and click the Filter button. This adds dropdown arrows to your headers, allowing you to hide rows based on specific values.
  3. Understand the Helper Logic: Because SUMIF cannot "see" if a row is hidden, we use SUBTOTAL(103, [cell]). The function number 103 tells Excel to count the cell only if it is visible. If the row is filtered out, it returns 0; if it is visible, it returns 1.
  4. Construct the Formula: To sum the "Sales Amount" (Column B) where the "Department" (Column A) is "Electronics", use the following syntax:

    =SUMPRODUCT((A2:A100="Electronics") * (SUBTOTAL(103, OFFSET(A2, ROW(A2:A100)-MIN(ROW(A2:A100)), 0))) * (B2:B100))

  5. Break Down the Formula Components:
    • (A2:A100="Electronics"): This is your "IF" criteria. It creates an array of TRUE/FALSE values based on whether the department matches your target.
    • OFFSET(A2, ROW(A2:A100)-MIN(ROW(A2:A100)), 0): This creates a reference to each individual cell in the range. This is necessary because SUBTOTAL usually takes a range, but we need it to evaluate each row one by one to check visibility.
    • SUBTOTAL(103, ...): This checks each individual cell generated by the OFFSET. If the row is visible, it returns 1. If hidden, it returns 0.
    • (B2:B100): This is the range of values you actually want to sum.
  6. Execute the Calculation: Press Enter. The result will now change dynamically. If you filter your list to show only a specific region or date, the total will update to reflect only the visible rows that also match the "Electronics" criteria.
  7. Test the Formula: Use the filter dropdown on your headers to hide a few rows. Observe the total changing. Then, change the filter to show everything and ensure the total matches a standard SUMIF calculation.

Common Mistakes

One of the most frequent errors is using the wrong function number within the SUBTOTAL part of the formula. Users often use 3 instead of 103. While 3 counts visible cells, 103 specifically ignores rows that have been manually hidden (Right-click > Hide) in addition to those hidden by a filter. For maximum reliability in dynamic reports, always use the 100-series function numbers.

Another common mistake is mismatched range sizes. If your criteria range is A2:A100 but your sum range is B2:B105, Excel will return a #VALUE! error. In a SUMPRODUCT array, every array must have the exact same dimensions. Double-check that your start and end row numbers are identical across all three parts of the formula.

Users also frequently forget that SUMPRODUCT handles arrays differently than standard formulas. If you are using a very old version of Excel (pre-2019/Office 365), you might feel the need to press Ctrl+Shift+Enter, though SUMPRODUCT generally handles this automatically. However, if you try to swap SUMPRODUCT for a standard SUM, the formula will fail unless entered as an array formula.

Tips

To make your formula more flexible, avoid hard-coding the criteria (like "Electronics") directly into the formula. Instead, point the formula to a cell. For example, if cell D1 contains the word "Electronics", change the formula to (A2:A100=D1). This allows you to change the category you are summing without editing the complex formula every time.

If you are working with a massive dataset (thousands of rows), the OFFSET function can slow down your workbook because it is a "volatile" function. This means it recalculates every time any cell in the entire workbook is changed. To improve performance, consider using a "Helper Column." Create a column called "Visible" and put =SUBTOTAL(103, A2) in every row. Then, you can use a much simpler SUMIFS formula that includes the helper column as a criteria (where Visible = 1).

For those using Excel Tables, replace the fixed ranges (A2:A100) with structured references (e.g., Table1[Department]). This ensures that as you add new rows to your data, the formula automatically expands to include the new entries without requiring manual updates to the range.

Troubleshooting

If your formula returns 0 when you expect a value, first check your criteria for typos. "Electronics " (with a trailing space) is not the same as "Electronics". Use the TRIM function on your data to remove accidental spaces if this is the case.

If you see a #VALUE! error, check for non-numeric data in your sum range. If there is a text string or an error like #N/A inside your sales column, SUMPRODUCT will fail. You can wrap your sum range in an IFERROR function or clean the data using Find and Replace to remove non-numeric characters.

If the total does not change when you filter the data, verify that you used the SUBTOTAL function inside the SUMPRODUCT. If you accidentally used a standard SUMIF, the formula will ignore the filter state and always sum every row that matches the criteria, regardless of whether it is hidden or visible.

If the formula is causing your Excel to lag or freeze, it is likely due to the volatile nature of the OFFSET function across a huge range. The best fix is to implement the helper column method mentioned in the Tips section, which replaces the complex array calculation with a simple binary (1 or 0) check in each row.

Frequently Asked Questions

Can I use this for counting instead of summing?

Yes. To count visible rows based on a criteria, simply remove the sum range (the B2:B100 part) from the formula. The multiplication of the criteria array and the visibility array will result in a series of 1s and 0s, which SUMPRODUCT will then total, effectively giving you a count.

Does this work with multiple criteria?

Absolutely. You can add more criteria arrays within the SUMPRODUCT function. For example, if you want to sum by "Electronics" AND "West Region", you would add another segment: (A2:A100="Electronics") * (C2:C100="West") * (SUBTOTAL(...)) * (B2:B100).

Why not just use a Pivot Table?

Pivot Tables are powerful, but they require a "Refresh" click to update when data changes. The SUMPRODUCT/SUBTOTAL combination is live; it updates the instant you change a filter or a value in a cell, making it better for real-time dashboards.

Will this work in Google Sheets?

The logic is similar, but Google Sheets handles arrays differently. You would likely need to wrap the formula in ARRAYFORMULA() and ensure the SUBTOTAL function is behaving as expected, as Google Sheets' implementation of SUBTOTAL can vary slightly from Excel's.

Can I use this to sum cells that are manually hidden?

Yes, provided you use the function number 103 (or 109 for sum). Function numbers 1-11 only ignore rows hidden by a filter; function numbers 101-111 ignore both filtered-out rows and rows that were hidden manually via the right-click menu.