# How to Calculate a Subtotal In Excel Using the Filter

Excel has many ways to calculate data. If you know the right formulas and functions, you can find out just about anything you want to know about your data. Todayâ€™s lesson is on using the subtotal formula to find various totals based on the filter option inÂ Excel.

Imagine you are running sales numbers using the following the spreadsheet:

If you remember from last weekâ€™s blog post on Sorting and Filtering data, we have gone ahead and added the filter. Now, if you wanted to find the sales total, you can use the following formula:

=sum(range)

This is the standard way to find a total. But, as you can see, once you use this formula and change the anything from the filtered drop-down menu, the sales total doesnâ€™t change with it:

So, how do you get the total to change with changes you make on the filter? This is where you will use the Subtotal formula. The Subtotal formula is:

=subtotal(function_number, ref1â€¦)

Note: You need to select which function you want the subtotal to use. For finding sums, we use function 9-Sum. As you can see from the following menu, there are multiple functions to choose from:

Once the function is selected it’s time toÂ enter the range. For the spreadsheet example, we are looking for subtotals on the Sales column, Column D. So, the final formula looks like this:

=subtotal(9,D2:D21)

When you first enter this formula in cell D22, it gives you the total amount, the same as when you enter the Sum formula. However, watch what happens when you change the options using the Filter drop-down:

As you can see, the Subtotal formula lets you find totals by Salesperson, Client, Product, etc. quickly and easily. And the total changes with the information you select.

We here at Learn Excel Now hope you found todayâ€™s tip on how to calculate a subtotal useful.