Sub topic 10
Add KPI Cells That Follow the Slicers
Assume you know how to navigate Google Sheets, reference another tab, and enter simple formulas. This chapter uses the Data tab from the dashboard example, where each row is one order and the columns include Order ID, Region, Category, Units, and Revenue.
A key performance indicator (KPI) is a number that summarizes an important result. Common dashboard KPIs include total revenue, order count, units sold, and average order value.
Why ordinary formulas do not work
A formula such as =SUM(Data!F2:F1000) adds every row in the range. It does not change when a slicer hides some rows. For a slicer-aware KPI, use SUBTOTAL.
SUBTOTAL calculates only the rows that remain visible after a filter. Its first argument is a function code. Code 109 means sum while ignoring filtered rows. Code 103 means count non-empty cells while ignoring filtered rows.
Place KPI formulas on the dashboard tab, outside the source range controlled by the slicer.
Total revenue:
=SUBTOTAL(109, Data!F2:F1000)
Order count:
=SUBTOTAL(103, Data!A2:A1000)
Units sold:
=SUBTOTAL(109, Data!E2:E1000)These formulas assume:
- Column A contains an order ID for every order.
- Column E contains numeric units.
- Column F contains numeric revenue.
- The slicer filters rows in
Data!A1:F1000.
If your source table has more rows, extend the ranges. Keep the range consistent with the slicer’s data range.
Calculate an average from visible rows
Average order value is total visible revenue divided by the number of visible orders. Wrap the division in IFERROR so the dashboard displays zero when a slicer combination leaves no rows.
=IFERROR(
SUBTOTAL(109, Data!F2:F1000) /
SUBTOTAL(103, Data!A2:A1000),
0
)Format the result as currency. Do not use AVERAGE(Data!F2:F1000) for this KPI because it includes filtered-out rows.
The count formula counts non-empty order IDs, not necessarily distinct orders. If one order can occupy several rows, this formula counts order lines. Use a source table with one row per order when you want an order count.
Place and label the KPI cells
A simple dashboard can place four KPI cells across its top area.
| KPI label | Formula pattern | Suggested format |
|---|---|---|
| Total revenue | `SUBTOTAL(109, revenue range)` | Currency |
| Order count | `SUBTOTAL(103, order ID range)` | Number |
| Units sold | `SUBTOTAL(109, units range)` | Number |
| Average order value | Visible revenue ÷ visible orders | Currency |
Put the label in one cell and the formula in the cell below it. Use a larger font for the result, bold labels, and consistent number formats. Add a note such as “Filtered view” if viewers might mistake the values for all-time totals.
Check the filter behavior
Test each KPI before sharing the dashboard:
- Clear all slicer filters and record the totals.
- Select one region or category.
- Confirm that the KPI values match the visible source rows.
- Select a combination that should return no rows.
- Confirm that the average formula displays
0rather than an error. - Clear the slicer and verify that the original totals return.
A slicer only affects formulas that use the filtered rows in its connected data range. A formula pointing to a separate summary table, fixed total, or unrelated range will not change.
Exercise
Write a formula for average revenue per visible order when order IDs are in Data column A and revenue is in Data column F.
Show answer
=IFERROR(SUBTOTAL(109, Data!F2:F1000) / SUBTOTAL(103, Data!A2:A1000), 0)