when I create a cumulative count plot via the user interface all works well. However, once I convert it into SQL the behaviour changes, and the table returned doesn’t have the cumultive count over time but rather the count (say of new users) week by week.
Next, we'll write a [SQL Server common table expression (CTE)] and use a window function to keep track of the cumulative sum/running total:
with data as (
select
convert(varchar(10), start_date, 105) as day,
count(1) as number_of_sessions
from sessions
group by convert(varchar(10), start_date, 105)
)
select
day,
sum(number_of_sessions) over (order by day asc rows between unbounded preceding and current row)
from data;