Subtotal and Aggregate Function in Excel

Learn how to use SUBTOTAL and AGGREGATE function in Excel to summarize data efficiently, with simple examples and expert tips for beginners.

When dealing with large data in Excel, it’s important to calculate subtotals, ignore hidden rows, and apply multiple types of summaries like average, count, max, or sum. Thankfully, Excel provides two very handy functions for this purpose:

  • SUBTOTAL()
  • AGGREGATE()

These functions are more flexible than standard formulas like SUM() or AVERAGE(), especially when working with filtered or hidden data. In this blog post, you’ll learn how each function works, when to use them, and how they can improve your productivity in Excel.


What is the SUBTOTAL Function in Excel?

Syntax:

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

  • function_num: A number (1–11 or 101–111) that specifies the summary operation (e.g., SUM, AVERAGE, etc.)
  • ref1, ref2, etc.: Ranges to include

All SUBTOTAL Function Numbers:

function_numSummary FunctionHidden Rows IgnoredDescription
1AVERAGEAverage including manually hidden rows
2COUNTCount numbers in all rows
3COUNTACount non-blank cells
4MAXMaximum value
5MINMinimum value
6PRODUCTProduct of values
7STDEVSample standard deviation
8STDEVPPopulation standard deviation
9SUMSum includes manually hidden rows
10VARSample variance
11VARPPopulation variance
101–111Same functionsIgnores manually hidden and filtered rows

Hidden Row Behavior Clarified

Code TypeFiltered RowsManually Hidden Rows
1–11IgnoredIncluded
101–111IgnoredIgnored

Conclusion:

  • Both sets ignore filtered-out rows.
  • Only 101–111 ignore manually hidden rows as well.

Example 1: Subtotal of Visible Sales

subtotal and aggregate function in excel
Result = 11000 (Filtered data)
ProductSales
A5000
B7000
C6000

If rows are filtered, this formula will only total visible ones:

=SUBTOTAL(109, B2:B4)

Result: Sum of only visible sales


What is the AGGREGATE Function in Excel?

The AGGREGATE() function goes beyond SUBTOTAL() by allowing:

  • More functions (like LARGE, SMALL, MEDIAN)
  • More control over ignoring errors, hidden rows, and nested SUBTOTAL/AGGREGATE functions

Syntax:

=AGGREGATE(function_num, options, ref1, [ref2], …)

  • function_num: Same concept as SUBTOTAL, with extended options
  • options: Controls what to ignore (errors, hidden rows, etc.)
  • ref1: The range

All AGGREGATE Function Numbers:

Function NumberSummary Function
1AVERAGE
2COUNT
3COUNTA
4MAX
5MIN
6PRODUCT
7STDEV.S
8STDEV.P
9SUM
10VAR.S
11VAR.P
12MEDIAN
13MODE.SNGL
14LARGE
15SMALL
16PERCENTILE.INC
17QUARTILE.INC
18PERCENTILE.EXC
19QUARTILE.EXC

AGGREGATE Options Explained:

Option NumberWhat It IgnoresDescription
0NothingIncludes hidden rows and errors
1Hidden rowsIgnores manually hidden rows
2Error valuesIgnores #DIV/0!, #N/A, etc.
3Hidden rows & error valuesBest for clean summary of visible good data
4Nested SUBTOTAL/AGGREGATE functionsIgnores nested subtotals
5Hidden rows + nested SUBTOTAL/AGGREGATEUseful in filtered nested reports
6Errors + nested SUBTOTAL/AGGREGATEFor error-prone data + subtotals
7Hidden rows + errors + nested functionsFull ignore mode for cleanest output

Example 2: Ignore Errors While Taking Average

Subtotal and Aggregate Function in Excel
NameScore
Ravi75
Meena#DIV/0!
Karan80

=AGGREGATE(1, 2, B2:B4)

Result: Average of 75 and 80 (ignores the error)


SUBTOTAL vs AGGREGATE: Key Differences

FeatureSUBTOTALAGGREGATE
Filters Aware
Ignores Hidden RowsOnly with 101–111✅ With option 1+
Supports Errors
More Functions❌ (limited)✅ (19 total)
Complex Ranges
Nested Support

Real-Life Use Cases

Example 3: Subtotal of Sales in a Filtered Table

Imagine you’re managing a small shop and have this sales data:

ProductCategorySales
PenStationery500
BookStationery800
T-ShirtApparel1500
JeansApparel2000

Now, suppose you filter the table to show only “Stationery” items (like Pen & Book).

If you use:

=SUBTOTAL(9, C2:C5)

This will sum only the visible rows (in this case, Pen and Book).

  • 9 stands for SUM
  • SUBTOTAL automatically ignores filtered-out rows

Result:

500 + 800 = 1300

Subtotal and Aggregate function in Excel
Filtered by Category = Stationery

Note: If you use SUBTOTAL(109, ...) and manually hide rows (not just filter), it will also ignore those manually hidden rows.

Example 4: Find 2nd Largest Visible Value

Sales
5000
7000
6500

=AGGREGATE(14, 1, B2:B4, 2)

Result: 6500 (2nd largest sales number ignoring hidden rows)


Tips and Best Practices

  • Use SUBTOTAL(109, range) for summing filtered data and hidden rows
  • Use SUBTOTAL(9, range) if hidden rows should still be included
  • Use AGGREGATE(1, 2, range) to ignore errors when averaging
  • Always match function_num correctly to what you want
  • Use AGGREGATE when your dataset might include errors

Download Practice File


Summary

SUBTOTAL and AGGREGATE Function in Excel are game-changers when analyzing filtered data, skipping errors, or needing flexible summaries. While SUBTOTAL is easier and perfect for filtered lists, AGGREGATE is more powerful and handles complex data scenarios.

Whether you’re a beginner or working on professional reports, mastering these functions will make your Excel work smarter and faster.

Also Read: Excel SUM Function


FAQs – Subtotal and Aggregate Function in Excel

It supports more functions (like LARGE, SMALL) and lets you control whether to ignore errors or hidden rows.

Yes. It updates automatically with filtered data.

AGGREGATE is available from Excel 2010 onwards.

Both ignore filtered rows, but 109 also ignores manually hidden rows. 9 will include those manually hidden with right-click > Hide.

What’s Next?

In the next post, we’ll learn about the Conditional Formatting in Excel

Spread the love

Leave a Comment

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

Translate »
Scroll to Top