What is Excel SUBTOTAL formula and 5 reasons why you should use it
Today we will learn Excel SUBTOTAL formula and 5 beautiful reasons why you should give it a try.
SUBTOTAL formula is used to find out subtotal of a given range of cells. You give SUBTOTAL two things – (1) a range of data (2) type of subtotal. In return, SUBTOTAL will give you the subtotal for that data.
Unlike SUM, AVERAGE, COUNT etc. which do one thing and only one thing, SUBTOTAL is versatile. You can use it to sum up, average, count a bunch of cells.
Here is the SUBTOTAL syntax:
=SUBTOTAL (TYPE OF TOTAL, RANGE OF CELLS)

So, for example, =SUBTOTAL(9,A1:A10) will give us the sum of all values in A1:A10, provided none are filtered(more on this filtering thing below). That is because “9″ stands for SUM in SUBTOTAL lingo. If you want a count of values, you can use “2″.
Hmm, that sounds like any other formula, what is so special about it?
Well, SUBTOTAL is not just any other formula, it is a special one. We don’t need to be Jedi masters to tell that force is with SUBTOTAL.
Here I have listed 5 reasons why this is such a special formula.
1) You can use SUBTOTAL to find sum of filtered values
I think the title says it all. See this example to know more.

2) You can use SUBTOTAL to ignore values in hidden rows
Often, we use hide rows feature in excel to remove irrelevant items from view. You can use SUBTOTAL with special type codes so that values in hidden rows are neglected.
For eg. SUBTOTAL(9,A1:A10) finds the sum of values in cells A1:A10 where as SUBTOTAL(109,A1:A10) will find sum of values in visible rows only.
3) You can use SUBTOTAL to dynamically summarize data
Since the “type of total” is a parameter to SUBTOTAL, we can use that to make a dynamic summary like this:

This is very handy in dashboards or when you don’t have space for everything.
4) If there are subtotals in SUBTOTAL range, they will be neglected

This is a killer feature of SUBTOTAL. If you have any SUBTOTAL formulas in the input range of another SUBTOTAL formula, these values are neglected so that double counting is avoided. Need I say more?
5) You can automatically create SUBTOTALs using Excel Data Tools
While SUBTOTAL formula looks kind of neat, writing them when you have tabular data can be a drag. But you don’t have to worry about that. In Excel’s Data menu / ribbon, there is an option on called “Subtotals” that automates the whole process for you.

To generate automatic SUBTOTALS, just select your table of data, go to Data ribbon (or menu) and click on “Subtotals”. This will launch a Subtotal dialog where you can easily specify the type of total grouping you want.
That simple!
Related Excel Formulas:
SUMPRODUCT | VLOOKUP | SUMIF & COUNTIF
Have you used SUBTOTAL formula?
I have never really bothered to test SUBTOTAL formula until few days ago. Now that I found some really cool uses for it, I am itching to implement some of them in future. What about you? Have you used SUBTOTAL formula before? Do you got any tips to share? Please use comments to discuss.
|
Comments
RSS feed for comments on this post. TrackBack URI
Leave a comment
If you have a question, please ask in the forums


At Pointy Haired Dilbert, I have one goal, "to make you awesome in excel and charting". PHD is started in 2007 and today has 300+ articles and tutorials on using excel, making better charts. 




I use SUBTOTAL all the time, could not live without it.
Another neat feature about SUBTOTAL is that you will be able to collapse/expand sections of your data set with the +/- buttons that magically appear to the left of the rows containing a subtotal which was created with the Data menu (Excel 2003).
I have been using the subtotal formula for years. It’s especially useful when you have very large lists. Instead of putting your SUBTOTAL function at the bottom of each row, place it at the top of the columns that you want totals, counts, averages, etc.
If you frequently extract data from transaction systems, for example, billing records – the subtotal function placed at the top of you data (above the headings) is a particularly useful way to summarize data in conjunction with filtering.
The only problem with SUBTOTAL is its inability to perform a SQL COUNTD (Count Distinct) function. This can be a big problem if you want to summarize (for example) billing records that include invoice line-item details.
Using Excel’s AVERAGE subtotal function will not result in the correct answer. It will compute the average of all of the rows in the list. In SQL, COUNTD effectively deals with this problem. I’ve read about some exotic methods that address this problem. All of them are a bit of a pain to implement.
A nice feature of using the Subtotal is that you can nest subtotals. Simply remove the check from the checkmark out of Replace Current Subtotals.
I LOVE subtotals!!! When I discovered them, really sped up a lot of my accounting work in a second. Thanks for this blog I share it with everyone I work with
Great post. I’ve never used SUBTOTAL much myself as I tend to jump straight to Pivot Tables, however your post has ensured I will be exploring it a bit more!
I love your posts and have learned so much from them. I am always eager to get the next one. My only suggestion is that you slow down the animation on the examples. They go so fast it is hard to quickly understand what you are trying to show us. Other than that…great job.
I have used subtotals in the past, but never dreamed they were so versatile. I never could figure out how to add subtotals while ignoring other subtotals in the range. Wow! This is great.
Great work on this XL stuff. I’ve been using SUBTOTAL for years, and especially together with Filters, they add powerful productivity to a spreadsheet full of too many numbers. I think a clarification is needed for this line: “So, for example, =SUBTOTAL(9,A1:A10) will give us the sum of all values in A1:A10, provided none are filtered(more on this filtering thing below).”
Actually, while it is true if nothing is filtered, =SUBTOTAL(9,A1:A10) is terrific in a filtering situation: as you add filtering, it does indeed change to reflect the filtered values. That is its strength. And as Dan said, put those SUBTOTALS at the top of the tables, above the Headers for example (with at least one blank row between them!), and they are then obvious to the reader, and already labelled.
As to using the “109″ function, to ignore “hidden” row data, I stay away from it, for two reasons: one, I don’t like a “Total”, or “SUBTOTAL”, showing that the reader cannot check on their own – if they find it doesn’t add up, their confidence in the entire spreadsheet is broken; two, I think sometimes when setting and resetting filters that these hidden rows become unhidden.
hth
Steve
I really like to use it to create reports for teachers’ testing data because it also will create a page break (when using the menu). I can download an entire school’s data, subtotal and print for each teacher in a matter of minutes . . . .
COL A COL B
a 100
a 50
SUBTOTAL 150
NOT A SUBTOTAL 1000
b 125
b 25
SUBTOTAL 150
c 145
c 5
SUBTOTAL 150
GRAND TOTAL 1450 ADDS EACH SUBTOTAL
FORMULA PLUS THE “NOT A
SUBTOTAL” ROW.
USE WITH CAUTION; THE “GRAND TOTAL” IS A SUBTOTAL FORMUA
FOR ALL OF THE ROWS. THE RESULT OF 1,450 IS CLEARLY MISLEADING.
Controlling the ‘Type of Total’ variable with option buttons is a great way of saving real estate on Dashboards & adding a small wow-factor to end user functionality.
@Dan… I have no idea about the COUNTD and other database functions. Never had the opportunity to use them either.
@Patricia: That is a good one, thanks for sharing it.
@Annie… Thanks for the love
@Glen.. yeah Subtotals are very robust. I have realized that only last week while doing something else.
@Campingshadow… thanks for your feedback. I will slow down the animations in later posts
@Steve.. good points. Yes, I know that subtotals work with filters amazingly well. I have mentioned that in the post further down.
Also, I have used totals at bottom so that it is easy to read in the post. But one can easily override that by un-checking “totals at bottom” box.
@Don.. If the value “1000″ doesnt contribute to SUBTOTALs, why is it part of the report?
@Justin: thanks…
“type of total” is a parameter to SUBTOTAL this working i cant do it pls. teach me
Thank you for this article. I use COUNTIFS and SUMIFS for most of my work as you can have tons of them and it won’t slow down the calculations like the DBSUM and DBCOUNT, etc always seem to do . Have not really explored SUBTOTAL but like what has been brought to our attention. I would be really, really be pleased to see the COUNTIFS and the SUMIFS idea extended to MIN, MAX, AVERAGE, STDEV, PRODUCT, and VAR. (filters in the formula, not because the database is filtered and rows hidden) Again, Thank you for this article.
I too did not used it before.
But as you have highlighted these good points about SubTotals I intend to use it more and more.
Thanks.
Tables such as shown in 5 with nested subtotals are frequently used to summarize data
For a small data set, one quick way of generating this is the use of ‘alt + =’ keyboard shortcut.
instead of manually typing formulas or using the wizard nested sum can be generated
The best part is when ‘alt + =’ is used for the grand total it adds up only the subtotals and not all the figures.
Hi, great post, but can you explain in a bit more detail how number 3 works? Or else provide a sample file?
Thanks in advance.
@Sachin & Kev23f: good question. Here is a bit more detail. If you are not able to reproduce it, I can post the file online.
In a bunch of cells define types of totals you want. For eg. say cells D1:D3 have,
Sum
Average
Max
Now, let us use the cell A1 to control what type of total you want. Go to A1, select data validation > list and then specify D1:D3 as the source range (this will ensure that only one these three values can be typed in the cell and also shows an in-cell drop down to select the values – here is a tutorial: http://chandoo.org/wp/2008/08/07/excel-add-drop-down-list/ )
Now, write a formula in another cell (where will show the result based on selected summary type) like this,
=CHOOSE(MATCH(A1,D1:D3,0),SUBTOTAL(for sum),SUBTOTAL(for avg), SUBTOTAL(for max))
Help on MATCH formula is here: http://chandoo.org/wp/2008/11/19/vlookup-match-and-offset-explained-in-plain-english-spreadcheats/