Explore this snippet with some demo data here.
Bar charts are perhaps the most common charts used in data analysis. They have one categorical or temporal axis, and one numerical axis. You just need a simple GROUP BY to get all the elements you need for a bar chart:
SELECT
AGG_FN(<COLUMN>) as metric,
<CATEGORICAL_COLUMN> as cat
FROM
<PROJECT.SCHEMA.TABLE>
GROUP BY
cat
where:
AGG_FN
is an aggregation function likeSUM
,AVG
,COUNT
,MAX
, etc.COLUMN
is the column you want to aggregate to get your metric. Make sure this is a numeric column.CATEGORICAL_COLUMN
is the group you want to show on the x-axis. Make sure this is a date, datetime, timestamp, or time column (not a number)
In this example with some Spotify data, we'll look at the average daily streams by month of year:
select
avg(streams) avg_daily_streams,
format_date('%m - %b', day) month
from (
select sum(streams) streams,
day
from spotify.spotify_daily_tracks
group by day
)
group by month