Math
SUBTOTAL function: sum filtered tables and prevent double-counting section totals
Use SUBTOTAL function codes (9 vs 109) so filtered views recalculate visible rows and grand totals skip nested section subtotals.
Why grand totals use SUBTOTAL instead of SUM
When a column contains section subtotals built with =SUBTOTAL(9, ...), wrapping the entire column in =SUBTOTAL(9, B2:B6) automatically ignores those nested SUBTOTAL cells so section totals are never double-counted.
By contrast, =SUM(B2:B6) blindly adds both raw rows and section subtotal rows, inflating the grand total.
=SUBTOTAL(9, B2:B6)Try the example
Use the original values or change them to test your understanding.