Finance Path · Mission 25 of 25Expert

Board-ready P&L capstone

Combine CTE, conditional aggregation, windows, and LEFT JOIN in one query

Back to Finance

The Brief

Priya ShahCFOslack-dm

Final boss. One query, by year-quarter 2023-2025: `year`, `quarter`, `revenue`, `cogs`, `opex`, `gross_profit` (revenue - cogs), `operating_income` (gross_profit - opex), `opex_budget` (summed from fact_budgets for that quarter), `budget_variance` (opex - opex_budget). Use LOWER() for the account_type filter. Posted only. Sort year, quarter.

You'll practice

Multi-CTE pipelinePivotCapstone

Tables available

fact_transactionsfact_budgetsdim_accounts

Hints (3)

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

Hint 1

Build a CTE for revenue/COGS/OpEx using CASE-inside-SUM, grouped by year-quarter.

Hint 2

Build another CTE for quarterly OpEx budget from fact_budgets (sum per quarter by EXTRACT).

Hint 3

LEFT JOIN the two CTEs on (year, quarter). Compute gross_profit, operating_income, budget_variance in the final SELECT.