Cumulative line chart
Learn how to build cumulative line charts to track growth and trends over time using SQL transformations for unique counts across months and countries.
SQL code to transform the data for creating a cumulative line chart
/* to display the cumulative number of unique campaigns per month and country */
select a.*, c.Cumulative_Campaigns from Table_Name a
left join
(select b.*, SUM(b.Unique_Campaigns) over ( partition by b.Country order by b.Month ) as Cumulative_Campaigns from
( select Month , Country , count(distinct Email_campaign_name ) as Unique_Campaigns
from Table_Name group by Month , Country ) b
) c
on a.Month = c.Month and a.Country = c.CountryFirst subquery (b)
Second subquery with window function (c)
Outer query
Last updated
Was this helpful?