Sub topic 3
Total Only the Visible Rows with SUBTOTAL
Assume you know worksheet ranges, column headers, basic formulas, and how to apply a filter. This chapter uses a sales list in A2:D100, with amounts in column D.
Total visible rows with SUBTOTAL
SUBTOTAL calculates an aggregate such as a sum while responding to filters. Function number 109 means “sum, ignoring filtered and manually hidden rows.”
=SUBTOTAL(109,D2:D100)Place the formula outside the filtered range. When you filter the list, the result updates to include only visible amounts.
Filter complex criteria with Advanced Filter
Advanced Filter uses a separate criteria range. Copy the source header exactly, then place the condition below it. Conditions on one row mean AND. Conditions on separate rows mean OR.
Region Amount
West >=500This criteria range keeps rows where Region is West and Amount is at least 500. In the Advanced Filter dialog, select the list range and the criteria range. You can filter the list in place or copy matching rows elsewhere.
Sort with formulas: SORT and SORTBY
Dynamic array formulas return a result that can spill into nearby cells.
=SORT(A2:C100,2,-1)This sorts the range by its second column in descending order. SORTBY sorts by one or more separate ranges:
=SORTBY(A2:C100,B2:B100,1,C2:C100,-1)This sorts column B ascending, then column C descending for ties.
Filter with formulas: FILTER
FILTER returns rows that meet a condition:
=FILTER(A2:C100,C2:C100>=1000,"No matches")For AND conditions, multiply Boolean tests:
=FILTER(A2:D100,(B2:B100="West")*(D2:D100>=500),"No matches")List distinct values with UNIQUE
Use UNIQUE to produce a live list without duplicates:
=UNIQUE(B2:B100)Troubleshooting
- Numbers stored as text may sort before or after real numbers unpredictably. Convert them to numbers before sorting.
- Merged cells interrupt rectangular ranges. Unmerge them and repeat the header in each row where needed.
- A partial selection can separate amounts from their related rows. Select the complete contiguous dataset, including every column that must move together.
Exercise
Which formula totals only visible amounts in D2:D100 after filtering?
Show answer
=SUBTOTAL(109,D2:D100)