Home Resource Centre How To Use The Subtotal Function in Excel

How To Use The Subtotal Function in Excel

The Subtotal function in Excel is a versatile tool that allows users to perform various calculations on data while excluding hidden or filtered rows. This guide will provide an in-depth look at the SUBTOTAL function, its syntax, and practical examples to help you master it.

What is the SUBTOTAL Function?

The Excel SUBTOTAL function is designed to return a calculated subtotal in a list or database. Unlike standard Excel functions, SUBTOTAL allows users to ignore hidden or filtered rows when performing calculations. It can execute various functions, such as SUM, AVERAGE, COUNT, and more, making it incredibly useful for dynamic reports and data analysis.

Why Use the SUBTOTAL Function?

Here are a few benefits of using the SUBTOTAL formula in your Excel workbooks:

Benefit Description
Dynamic Calculations Automatically adjusts calculations based on visible data.
Multiple Functions Offers 11 different functions (e.g., SUM, AVERAGE).
User-Friendly Easy to implement and understand for all skill levels.
Nested Subtotals Ignored Automatically excludes other SUBTOTAL formulas within the range.

SUBTOTAL Function Syntax

The SUBTOTAL function syntax is as follows:

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

  • function_num: This is required and determines the type of calculation you want to perform (like SUM, AVERAGE, etc.).

  • ref1: This is the first range of cells you want to calculate the subtotal for.

  • ref2, ...: Optional additional ranges for which you want to apply the subtotal formula.

21 Function Numbers And Their Uses

Excel provides several function numbers to perform specific calculations. Here’s a handy table showing different function numbers and their corresponding actions:

Function Type Function Number (Includes Hidden Rows) Function Number (Excludes Hidden Rows) Description
AVERAGE 1 101 Calculates the average of a range of cells.
COUNT 2 102 Counts the number of cells that contain numbers.
COUNTA 3 103 Counts the number of non-empty cells.
MAX 4 104 Returns the maximum value from a range of cells.
MIN 5 105 Returns the minimum value from a range of cells.
PRODUCT 6 106 Multiplies all numbers in a range and returns the total.
STDEV 7 107 Estimates standard deviation based on a sample.
STDEVP 8 108 Calculates standard deviation based on an entire population.
SUM 9 109 Adds all numbers in a specified range.
VAR 10 110 Estimates variance based on a sample.
VARP 11 111 Calculates variance based on an entire population.
MEDIAN 12 112 Returns the median value from a range of cells.
MODE 13 113 Returns the most frequently occurring value in a range.
LARGE 14 114 Returns the k-th largest value in a data set.
SMALL 15 115 Returns the k-th smallest value in a data set.
SUMIF 16 116 Adds all numbers in a range that meet specified criteria.
COUNTIF 17 117 Counts the number of cells that meet specified criteria.
AVERAGEIF 18 118 Calculates the average of cells that meet specified criteria.
COUNTIFS 19 119 Counts cells that meet multiple criteria across ranges.
SUMIFS 20 120 Adds values based on multiple criteria across ranges.
GEOMEAN 21 121 Returns the geometric mean of a set of values.

These function numbers give you flexibility. For example, if you want to SUM visible rows only, you have to use 9. If you want to SUM all rows, including hidden ones, you have to use 109.

How to Use the SUBTOTAL Function

Follow these simple steps to start using the Excel SUBTOTAL formula:

Step 1: Open Your Excel Worksheet

  • Launch Excel and open your worksheet containing data.

Step 2: Select an Empty Cell

  • Click on an empty cell where you want your subtotal value to appear.

Step 3: Start Typing the Formula

  • Type =SUBTOTAL( into the selected cell.

Step 4: Choose Your Function Number

  • Decide which function you want to use by selecting a function number from the table above. For example, use 9 for summing visible cells.

Step 5: Specify the Range

  • After entering the function number, add a comma and select your data range.

  • Example: =SUBTOTAL(9, A2:A10) will sum all values in cells A2 through A10.

Step 6: Close Parenthesis and Press Enter

  • Complete your formula by closing the parenthesis: =SUBTOTAL(9, A2:A10).

  • Hit Enter to calculate your subtotal.

Step 7: Using Multiple Ranges (Optional)

  • You can subtotal multiple ranges by separating them with commas.

  • Example: =SUBTOTAL(9, A2:A10, B2:B10).

Subtotal Feature: Filtering Data with Ease

One of the best uses of the SUBTOTAL formula is when working with filtered data. Suppose you have a long subtotal list of products and you apply a filter to display only items above a certain price point. The SUBTOTAL formula will adjust automatically, calculating only the visible, filtered rows.

Aggregate Functions in Excel

While the Excel SUBTOTAL function is sometimes compared to aggregate functions, the key difference lies in its ability to ignore hidden rows. The Excel aggregate function can also summarize data, but SUBTOTAL is a more dynamic tool for working with filtered datasets.

Aggregate Function SUBTOTAL Function
Primarily used for summarizing datasets, including options for ignoring errors or nested subtotals. It focuses on summarizing visible data and excluding hidden or filtered rows.

Summary Functions in Excel

The SUBTOTAL function serves as a summary function that simplifies data analysis by allowing users to quickly calculate totals without affecting filtered data sets. This feature is particularly valuable when working with large datasets where visibility into specific entries is crucial.

Common Mistakes to Avoid

When using the SUBTOTAL formulas, be mindful of these common mistakes:

  1. Incorrect Function Numbers: Ensure you choose correctly between including or excluding hidden rows.

  2. Not Refreshing Formulas After Filtering: Always refresh your formulas after changing filters.

  3. Ignoring Nested Subtotals: If there are other SUBTOTAL formulas within your specified ranges, they will be ignored to prevent double counting.

Practical Examples of Using SUBTOTAL

Here are some practical examples of how to use the Excel SUBTOTAL function effectively:

  1. To calculate the sum of visible sales data:

    =SUBTOTAL(9, B2:B100) // Includes hidden rows =SUBTOTAL(109, B2:B100) // Excludes hidden rows

  2. To find the average of visible sales data:

    =SUBTOTAL(1, C2:C100) // Includes hidden rows =SUBTOTAL(101, C2:C100) // Excludes hidden rows

  3. To count visible entries:

    =SUBTOTAL(2, D2:D100) // Includes hidden rows =SUBTOTAL(102, D2:D100) // Excludes hidden rows

Conclusion

The Excel SUBTOTAL function is a powerful, dynamic tool that simplifies data analysis and summary functions. By mastering its syntax and understanding how to apply it in real-world scenarios, you can significantly improve your data management skills.

Whether you are calculating subtotal rows or working with complex filtered lists, SUBTOTAL is your go-to formula for efficient data handling. Give it a try today, and watch your Excel workflow become faster and more accurate!

Here are 5 suggested reads that will help you up your Excel game:

Shivangi Vatsal
Sr. Associate Content Strategist @Unstop

I am a storyteller by nature. At Unstop, I tell stories ripe with promise and inspiration, and in life, I voice out the stories of our four-legged furry friends. Providing a prospect of a good life filled with equal opportunities to students and our pawsome buddies helps me sleep better at night. And for those rainy evenings, I turn to my colors.

Updated On: 21 Oct'24, 06:36 PM IST