Business Intelligence Path · Mission 21 of 25Expert

Year-over-year revenue by quarter

Combine LAG with PARTITION BY for YoY comparison within partitioned groups

Back to Business Intelligence

The Brief

Rachel TorresCFOfinance-analytics

I need year-over-year quarterly revenue comparison. For each quarter (Q1 through Q4), show the year, quarter, quarterly revenue, prior year's same-quarter revenue, and the YoY growth percentage. Q1 2023 should show NULL for prior year since we have no 2022 data. This is the single most important chart for the board.

You'll practice

LAG()PARTITION BYYoY

Tables available

fact_sales

Hints (3)

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

Hint 1

Aggregate revenue by year and quarter in a subquery first

Hint 2

Use LAG(quarterly_revenue, 1) OVER (PARTITION BY quarter ORDER BY year) — PARTITION BY quarter ensures you compare Q1 to Q1, Q2 to Q2, etc.

Hint 3

YoY growth = (current - prior) / prior * 100