How to SUM Only Visible (or Filtered) Rows Using SUBTOTAL

Using SUBTOTAL to SUM a Filtered Table

Let’s try replacing SUM with SUBTOTAL in the Total row of the table. First, we should remove the filter on Region so we can work with the entire table at once. Click on the filter icon by the Region header, choose the Select All option in the drop-down menu, and click OK.

Filter Select All

The SUBTOTAL function in Excel works as a kind of master function for many others. It can perform the same function as AVERAGE, COUNT, COUNTA, MAX, MIN, PRODUCT, STDEV, STDEVP, SUM, VAR, and VARP, all while taking into consideration hidden and filtered rows.

The syntax for SUBTOTAL is as follows:

=SUBTOTAL(function_num, ref1, [ref2],...)

The function_num indicates which type of calculation you would like to perform. It has two sets of values. One- and two-digit values calculate only values that show in the filtered table, but they also include any manually hidden rows in the spreadsheet. Three-digit values indicate that SUBTOTAL should ignore both filtered rows and any rows that are manually hidden. In other words, with three-digit values, what you see is what you get.

A summary of the potential values of function_num is below:

SUBTOTAL Functions

In this example, we want the SUM calculation from SUBTOTAL. Since we are only dealing with filtered rows and not hidden rows, both 9 and 109 will work equally well. Let’s replace the calculations in the Total row.

SUBTOTAL Formula

Underneath the column for each year, type the SUBTOTAL function, indicate 9 for the function_num, and select the range of cells in the table for the corresponding year. The data table will convert that cell range (normally, D3:D28) to it’s Data Table range name. Repeat the process for each year’s column.

Re-filter the data, and you’ll find that the Total row re-calculates to provide the correct values! SUBTOTAL can just as easily be used to compute averages, find the maximum or minimum values among those on display, and more!

Filtered Total Correct

Get the latest Excel tips and tricks by joining the newsletter!

Andrew Roberts ThumbnailAndrew Roberts has been solving business problems with Microsoft Excel for over a decade. Excel Tactics is dedicated to helping you master it. You can read more of his writing on his personal blog at NapkinMath.io.

Join the newsletter to stay on top of the latest articles. Sign up and you'll get a free guide with 10 time-saving keyboard shortcuts!

12 thoughts on “How to SUM Only Visible (or Filtered) Rows Using SUBTOTAL

  1. ok, try adding a dummy column with a subtotal, example in row 10: =subtotal(103;a10)

    now you have another criteria depending on the filter, so all multi-criteria formulas will work as well, far beyond the ones provided with subtotal!

    enjoy…

    1. hey it works brilliantly what you told, but if I drag the same formula for the entire Column, Excel doesn’t accept that.

      1. It is like any other formula, copy the couple first ones so 103 doesn’t change, then pick them all and drag. It really wants no special treatment.
        Spread the word and enjoy!!!

  2. Hi There,

    I’m trying to add a total from each separate tab on my spreadsheet to give a summary of the totals on a final tab, if for some reason one of the tabs is removed / deleted it throws out the formula on the final sheet as the tab its looking for no longer exists. How do I tell Excel to ignore deleted tabs?

    Any help would be appreciated, I am afraid I’m a novice on excel and just getting to grips with the basics it seems!

    Thanks

    Sam

    1. hi, although out of topic I’ll give a simple and effective answer:
      rap individual sums in IfError()
      example instead of: =sum(Sheet1!B11,Sheet2!B11)
      write: =sum(IFERROR(Sheet1!B11,0),IFERROR(Sheet2!B11,0))
      and so on…

  3. Is it possible to have a separate tab that would show the running total for each region? So if you added something onto East it would automatically add it on and update the other tab? Or would you need to have totals on that page for it to work?

  4. Hi,

    I want to show the filtered value in a separate cell.. say from the above example if we filter data on “WEST”, i want “WEST” to be shown in separate cell (dynamically, that cell should show filtered data what is filtered). Glad if this is possible thru formulas (not VBA)

    Prasad

  5. Hello there..kindly help me on this: I want to grade only 7 subjects out of 11. 4 are core the rest are optional and a student must therefore till they’re a minimum of 7. I will be glad if you reply to my email too.

  6. I want to use the AVERAGEIF, SUMIF AND COUNTIF functions but want them to only apply to the visible data on a filtered table. How do i do this?

  7. if i want to skip “William Foster” in above table and subtotal automatically skip “William Foster” and add “Robert” to do the sum of last 4 managers…..
    is it possible??

Leave a Reply

Your email address will not be published. Required fields are marked *