A dashboard can show a number without showing why it changed. A drilldown view gives a data-comfortable user a way to investigate beyond summary metrics and charts. Rather than crowding the main dashboard, it provides a detailed table for exploring selected dimensions and metrics. section 7.5 section 7.5.2
Investigating a sales question
Suppose a fountain-pen campaign targeted women in two older age groups. A chart can break sales down by age or by gender, but the question calls for both—and for a comparison between products. Selecting age group, gender, and product name as table dimensions makes that combination available for inspection. section 7.5.2
The table behaves like a flexible pivot table: users choose which dimensions define its rows, while key metrics appear together as columns. It shows aggregated values for each combination, not an unfiltered dump of source rows. With no dimensions selected, it shows metrics for the entire supplied dataframe. section 7.5.2 section 7.5.3
def get_aggregate_metrics(df, dimensions):
if dimensions:
grouped = df.groupby(dimensions)
return grouped.apply(get_metric_cols).reset_index()
metric_cols = get_metric_cols(df)
return pd.DataFrame(metric_cols).T
The aggregation function groups a pandas dataframe by the selected dimensions and calculates metrics for each group. Its other branch handles an empty selection by returning one row of overall metrics. section 7.5.3
Build the interface incrementally: collect dimensions with a Streamlit multiselect, calculate each configured metric for every group, then display the result in a dataframe. Separate Main and Compare tabs show tables for their respective dataframes; an unavailable selection produces a warning instead of a table. section 7.5.3
Add a Total row calculated from the full dataframe, then format metric values and shade that row so it is easy to distinguish from the breakdown. Computing the total through the metric functions preserves their calculations rather than simply adding displayed group values. section 7.5.3
