Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 1.13 KB

horizontal-bar.md

File metadata and controls

36 lines (28 loc) · 1.13 KB

Horizontal bar chart

Explore this snippet with some demo data here.

Description

Horizontal Bar charts are ideal for comparing a particular metric across a group of values. They have bars along the x-axis and group names along the y-axis. You just need a simple GROUP BY to get all the elements you need for a horizontal bar chart:

SELECT 
   AGG_FN(<COLUMN>) as metric,
   <GROUP_COLUMN> as group
FROM 
   <PROJECT.SCHEMA.TABLE>
GROUP BY
   group

where:

  • AGG_FN is an aggregation function like SUM, AVG, COUNT, MAX, etc.
  • COLUMN is the column you want to aggregate to get your metric. Make sure this is a numeric column.
  • GROUP_COLUMN is the group you want to show on the y-axis. Make sure this is a categorical column (not a number)

Usage

In this example with some Spotify data, we'll compare the total streams by artist:

select
  sum(streams) streams, 
  artist 
from spotify.spotify_daily_tracks
group by artist

horizontal-bar