Business Intelligence Path · Mission 13 of 25Medium

Monthly revenue trend with growth rate

Use LAG() window function for period-over-period comparison and date truncation

Back to Business Intelligence

The Brief

Rachel TorresCFOfinance-analytics

I need a monthly revenue trend with month-over-month growth rates for the board. For each month, show the year, month number, monthly revenue, previous month's revenue, and the MoM growth percentage. Order chronologically. The first month will naturally have NULL for prior month — that's fine.

You'll practice

LAG()Date truncationGrowth

Tables available

fact_sales

Hints (3)

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

Hint 1

Extract year and month from sale_date, GROUP BY them, and SUM revenue to get monthly totals

Hint 2

Use LAG(monthly_revenue) OVER (ORDER BY year, month) to get the previous month's value

Hint 3

Growth rate = (current - previous) / previous * 100. Use a subquery: aggregate in the inner query, apply LAG in the outer