Business Intelligence Path · Mission 20 of 25Hard

Running revenue total by month

Use SUM() OVER with window frame clause to compute running totals

Back to Business Intelligence

The Brief

Rachel TorresCFOfinance-analytics

The board wants to see cumulative revenue growth. For each month, show the year, month, monthly revenue, and a running total of revenue from the very first month through the current month. Order chronologically. This is the classic 'how much total revenue have we earned so far' chart.

You'll practice

SUM() OVERWindow frame

Tables available

fact_sales

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

First aggregate revenue by year and month in a subquery

Hint 2

Then apply SUM(monthly_revenue) OVER (ORDER BY year, month ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) for the running total

Hint 3

The window frame ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW is the default for ORDER BY, but it's good practice to be explicit