Make selections compose predictably, recalculate numerators and denominators, and expose the active state.
Interactive dashboards: recompute cohorts after linked filters
A selection changes the population
Linked filtering lets a selection in one view constrain another. Clicking a depot, brushing a date range or choosing a channel changes the cohort behind every plotted metric. The interaction contract must specify whether filters combine with AND or OR, whether a second click toggles, and whether an empty selection means all or none. Show active filters in text and offer a clear reset. Dashboard provenance needs the same filter state that the user sees; otherwise a shared screenshot cannot be reproduced.
Recompute base counts
A precomputed overall completion percentage cannot simply be filtered and averaged. Reapply the filter to eligible records, then sum timely and eligible counts for the selected cohort. If a record appears in both a status log and an order table, deduplicate to the declared unit before counting. Grain and denominator rules are the invariant under interaction. A filtered group with zero eligible records should display an undefined rate and zero denominator, not a zero-percent success rate.
Synchronize every view
When a brush narrows a chart, its companion count, data table, map and export must use the same selected IDs or query predicate. Some dashboards filter the marks but leave the headline KPI unfiltered; users then compare incompatible populations. Carry one normalized state object and one data-version token into each query. If a backend response arrives after the user changes filters again, discard the stale response instead of replacing a newer view. A request ID or abort signal can enforce this. Large-series rendering may be approximate, but filter semantics must remain exact.
Make selection discoverable and reversible
Hover-only behavior hides controls from touch and keyboard users. Provide visible filter chips, keyboard-operable controls, focus cues and a readable selection summary. Color should not be the sole indication of selected marks. A reset should restore the documented default and preserve the date or snapshot policy, not silently switch to today's data. Accessible chart controls include data values outside the plotted canvas. Keep the browser back button or a shareable query state when deep analysis paths matter.
Test the state machine
Exercise no filters, one filter, two intersecting filters, mutually exclusive filters, a zero-eligible result, and rapid filter changes. Compare chart, KPI and export row counts for each state. For a selected region and channel, check that removing one chip broadens the cohort only along that dimension. Record the expected query predicate alongside a screenshot in a release test. If the chart is based on sampled or aggregated data, do not use a pixel brush to imply record-level exactness unless the backend can resolve it.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class ReviewRecord:
receipt_id: str
region: str
channel: str
eligible: bool
timely: bool
def filtered_completion(records: list[ReviewRecord],
regions: set[str], channels: set[str]
) -> tuple[int, int, float | None]:
if len({record.receipt_id for record in records}) != len(records):
raise ValueError("duplicate receipt identity")
selected = [record for record in records
if (not regions or record.region in regions)
and (not channels or record.channel in channels)
and record.eligible]
if any(record.timely and not record.eligible for record in records):
raise ValueError("timely receipt cannot be ineligible")
timely = sum(record.timely for record in selected)
eligible = len(selected)
return timely, eligible, timely / eligible if eligible else None
receipts = [ReviewRecord("r-47", "north", "web", True, True),
ReviewRecord("r-81", "north", "store", True, False),
ReviewRecord("r-94", "south", "web", True, True)]
assert filtered_completion(receipts, {"north"}, {"web"}) == (1, 1, 1.0)
assert filtered_completion(receipts, {"south"}, {"store"}) == (0, 0, None)Performance and operating cost
For N records, duplicate validation and filtering take O(N) expected time and O(N) temporary space in this direct version; the selected list can be avoided with streaming counters to use O(N) identity state and O(1) additional cohort state. For a remote dashboard, query cost and transfer volume usually dominate. Cache only by normalized filters, authorization context and data version. Never reuse a cached result across tenants or revisions merely because the visible filter chips match.
Common Mistakes
- Filtering colored marks while leaving headline metrics on the full population.
- Averaging cached percentages after a filter instead of summing base counts.
- Treating an empty cohort as a measured zero-percent rate.
- Letting an older network response overwrite the result of a newer selection.
Validation drill
Connect a weekly trend, region bar chart and completion KPI. Test six filter states and verify the same eligible count in the chart tooltip, KPI, table and CSV export for each state.
Read next
- Dashboard filters and provenance: make every view reproducible
- Aggregation grain and denominator: make every plotted mark auditable
- Accessible charts: encode meaning without relying on color alone
- Chart exports: carry the data, filters and render contract together
Continue this visualization path
- Parallel coordinates: make every axis conversion inspectable
- Interactive charts: make selection work without a pointer
- Confusion matrices: fix class order, denominators and abstentions
- Cohort retention heatmaps: keep immature cells blank
- Waffle charts: allocate whole cells without losing the total
- Alluvial diagrams: follow one cohort through categorical stages
