# SUBTOTAL Formula

The mention of the subtotal formula will probably cause you to relate the formula to calculating the total for sub-groups of data. This is generally true. But the formula can also be used to calculate average, count numbers, count text and number, find maximum, find minimum, addition and 5 other types of calculation. That was what our participants in "Hidden Secrets in Data Analysis with Excel" found out. Neither do they think they should be trained in this formula or realised how powerful it can become when it is combined with the auto-filter function.

Let me share with you what is this formula and how it works.

Subtotal formula requires 2 basic inputs, the function number and a range.

The function number determines the type of calculation to be performed with the formula. If the function number 1 is used, it calculates the average of the numbers found in the range listed. If the function number is 2, it is used to count numbers. See below for the complete list of calculations you can do with formula.

 Function Number Function Meaning 1 AVERAGE Average value for the filtered range 2 COUNT Count the number of cells that contain values in the filtered range 3 COUNTA Count the number of non-blanks cells in the filtered range 4 MAX Returns the max value in the filtered range 5 MIN Returns the min value in the filtered range 6 PRODUCT Multiplies the values in the filtered range 7 STDEV Returns the standard deviation for the sample in the filtered range 8 STDEVP Returns the standard deviation for the population in the filtered range 9 SUM Returns the sum of all the values in the filtered range 10 VAR Returns the variance for the sample in the filtered range 11 VARP Returns the variance for the population in the filtered range

The range defines the cells that should be involved in the calculation. This is usually entered as one continuous range. But it doesn't have to be limited to one continuous range. You can list multiple ranges in the formula.

From the above explanation, you probably think that it is a good substitute for the SUM, COUNT, COUNTA, AVERAGE formulas. That is true if you are using it in isolation. But if you use the Subtotal formula together with Auto-filter, it will calculate the results based on the filtered rows only. Hidden rows are excluded from the calculation even though the range is included in the formula.

For example, in a list of 20 items, the Subtotal formula will return 20 as the answer. The COUNTA formula will also return the result as 20. But if you filter the list based on a certain criteria, some of the rows are hidden. If you look at the Subtotal formula again, you will find that it counts the number of rows that are visible to you. As for the COUNTA formula, it continues to show the number 20.

Learn about the SUBTOTAL function. ### New! Comments

Have your say about what you just read! Leave me a comment in the box below.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8807466,"math_prob":0.9739921,"size":2933,"snap":"2019-35-2019-39","text_gpt3_token_len":632,"char_repetition_ratio":0.19358143,"word_repetition_ratio":0.048828125,"special_character_ratio":0.21445619,"punctuation_ratio":0.08141593,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9971164,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-08-19T16:59:19Z\",\"WARC-Record-ID\":\"<urn:uuid:ef6c5495-516c-4064-a077-8ebd08562129>\",\"Content-Length\":\"21054\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:fdd3f892-4699-4ce3-b420-933704e4d8d3>\",\"WARC-Concurrent-To\":\"<urn:uuid:b5a3a9c0-0599-4fed-96bf-6a317895de85>\",\"WARC-IP-Address\":\"173.247.219.19\",\"WARC-Target-URI\":\"https://www.advanced-excel.com/subtotal.html\",\"WARC-Payload-Digest\":\"sha1:MOBDQ4KGNUQEW5EI4B7NGL2EIKFM25X6\",\"WARC-Block-Digest\":\"sha1:4M2YB4W3C6D5X5NLULMPCPV3IG5FIHVB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-35/CC-MAIN-2019-35_segments_1566027314852.37_warc_CC-MAIN-20190819160107-20190819182107-00284.warc.gz\"}"}