Explore this snippet with some demo data here.
100% bar charts compare the proportions of a metric across different groups.
To build one you’ll need:
- A numerical column as the metric you want to compare. This should be represented as a percentage.
- 2 categorical columns. One for the x-axis and one for the coloring of the bars.
SELECT AGG_FN(<COLUMN>) as metric, <XAXIS_COLUMN> as x, <COLOR_COLUMN> as color, FROM <PROJECT.SCHEMA.TABLE> GROUP BY x, color
AGG_FNis an aggregation function like
COLUMNis the column you want to aggregate to get your metric. Make sure this is a numeric column. Must add up to 1 for each bar.
XAXIS_COLUMNis the group you want to show on the x-axis. Make sure this is a date, datetime, timestamp, or time column (not a number)
COLOR_COLUMNis the group you want to show as different colors of your bars.
In this example with some tennis data we’ll see what percentage of matches won for the world’s top tennis players come on different surfaces.