Combine SUMIF and SUBTOTAL in Excel

Formulas & functions · Updated November 22, 2026

Combining SUMIF and SUBTOTAL lets you sum values that meet a condition (like a product category or region) while ignoring rows hidden by a filter. This is essential for interactive dashboards where you filter data and want totals to update automatically. The standard approach uses SUBTOTAL with the OFFSET function to create a range that only includes visible rows, then feeds that into SUMIF. In this guide, you’ll learn the exact formula, how to set it up, and common pitfalls to avoid.

What You’ll Need

  • Microsoft Excel 365, Excel 2021, Excel 2019, or Excel 2016 (the formula works in all modern versions). Mac and Excel for the web support the same functions.
  • A dataset with at least one column for criteria (e.g., category) and one numeric column to sum.
  • Basic familiarity with entering formulas and using the Filter button (Data > Filter).

Step-by-Step

  1. Prepare your data. Ensure your data is in a contiguous range with headers in row 1. For this example, assume column A contains categories (e.g., “Fruit”, “Vegetable”) in A2:A20, and column B contains sales amounts in B2:B20. Your data should be in rows 2 through 20.
  2. Apply a filter. Select any cell in your data range, go to the Data tab, and click Filter. This adds dropdown arrows to your header row. You can now filter rows by any column.
  3. Understand the core formula. The combination uses SUBTOTAL with function number 9 (SUM) or 109 (SUM, ignoring manually hidden rows). The trick is to make SUBTOTAL evaluate each cell individually, which is done using OFFSET to create a range of single cells. The formula is:
    =SUMPRODUCT(SUBTOTAL(9,OFFSET(B2,ROW(B2:B20)-ROW(B2),0,1)),--(A2:A20="Fruit"))

    This sums the visible values in B2:B20 where A2:A20 equals “Fruit”. Let’s break it down.

  4. Enter the formula correctly. In a cell outside your data (e.g., E2), type the formula above. Press Ctrl+Shift+Enter if you are using Excel 2019 or earlier, because OFFSET returns an array. In Excel 365, you can press Enter normally; the formula will spill or work as a dynamic array. For this example, assume the result is 150, meaning the visible “Fruit” sales total 150.
  5. Adjust the criteria. Replace "Fruit" with any text or cell reference. For example, if you put a category name in D2, use --(A2:A20=D2) instead of the hardcoded text.
  6. Test with filtering. Click the filter arrow in column A, uncheck some categories, and press OK. The formula result should update to reflect only the visible rows that also match the criteria. If it doesn’t, check the next steps.
  7. Use function number 109 for manually hidden rows. If you also want to ignore rows hidden by right-clicking a row and choosing “Hide”, replace 9 with 109 in the formula. The difference: 9 ignores only filtered-out rows; 109 ignores both filtered and manually hidden rows.

Common Mistakes

  • Using SUMIF directly on a filtered range. SUMIF ignores filters entirely; it sums all matching cells, hidden or not. That’s why you need the SUBTOTAL wrapper.
  • Forgetting to press Ctrl+Shift+Enter in older Excel. If you don’t array-enter the formula, it may return a #VALUE! error or only sum the first cell.
  • Misaligned ranges. The OFFSET range and the criteria range must be exactly the same size and start on the same row. If you use A2:A20 for criteria but B2:B21 for values, the formula will return wrong results or an error.
  • Using whole-column references. OFFSET(B:B,...) can cause performance issues and may not work correctly with array formulas. Stick to a defined range.
  • Not using double unary (–). The -- converts TRUE/FALSE to 1/0. If you omit it, the multiplication may still work, but it’s safer to include it for clarity and to avoid text results.

Tips

  • Use a helper column for complex criteria. If you need multiple conditions, create a helper column that flags rows with a formula like =AND(A2="Fruit",C2="Organic"), then use that column as the criteria range.
  • Name your ranges. Select A2:A20, type Category in the Name Box (left of the formula bar), and press Enter. Do the same for B2:B20 as Sales. Then the formula becomes easier to read: =SUMPRODUCT(SUBTOTAL(9,OFFSET(Sales,ROW(Sales)-MIN(ROW(Sales)),0,1)),--(Category="Fruit")).
  • For Excel 365, consider the FILTER function. If you have Microsoft 365, you can use =SUM(FILTER(B2:B20,(A2:A20="Fruit")*SUBTOTAL(3,OFFSET(B2,ROW(B2:B20)-ROW(B2),0)))) — but the SUMPRODUCT method is more compatible with older versions.
  • Use a table for dynamic ranges. Convert your data to a Table (Ctrl+T). Then use structured references like Table1[Sales], but note that the OFFSET approach still works with table ranges.
  • Test with a simple filter. Before relying on it, filter to show only one row and manually verify the sum.

Troubleshooting

  • Formula returns #VALUE!. This usually means you didn’t array-enter in older Excel. Select the cell, press F2, then Ctrl+Shift+Enter. In Excel 365, ensure you’re not mixing dynamic arrays with implicit intersection.
  • Result doesn’t change when filtering. Check that you used SUBTOTAL and not SUM inside the formula. Also, make sure your filter is actually applied to the same data range.
  • Result is 0 even though visible rows match. Verify that the criteria text matches exactly (case-insensitive but no extra spaces). Use TRIM if needed. Also check that the ranges start at the same row.
  • Formula is too slow. If you have thousands of rows, the OFFSET array can be heavy. Limit the range to your actual data size, or use a helper column with =SUBTOTAL(3,A2) and then SUMIFS on that helper.
  • Getting a spill error in Excel 365. If you enter the formula and see #SPILL!, it means something is blocking the dynamic array result. Move the formula to an empty cell with space below.

Frequently Asked Questions

Can I use SUMIFS instead of SUMIF with this method? Yes. Replace the criteria part with multiple conditions. For example, =SUMPRODUCT(SUBTOTAL(9,OFFSET(B2,ROW(B2:B20)-ROW(B2),0,1)),--(A2:A20="Fruit"),--(C2:C20="Organic")).

Does this work with numbers as criteria? Yes, just use --(A2:A20=100) or reference a cell containing the number.

Why do I need the double unary (–)? It converts TRUE/FALSE to 1/0. Without it, the multiplication still works in most cases, but the formula can return text values or errors in some versions. It’s a best practice.

Can I use this with a PivotTable? No, PivotTables have their own filtering system. This formula is for regular ranges with AutoFilter.

What if I want to sum visible rows only, without any criteria? Just use =SUBTOTAL(9,B2:B20) — no need for the OFFSET trick.

Does this work in Google Sheets? Yes, but the syntax is slightly different. In Google Sheets, use =SUMPRODUCT(SUBTOTAL(9,OFFSET(B2,ROW(B2:B20)-ROW(B2),0,1)),--(A2:A20="Fruit")) — it works the same way, but you don’t need Ctrl+Shift+Enter.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.