Finance Path · Mission 10 of 25Easy

Gross margin by quarter

CASE expressions + date bucketing for P&L-style aggregation

Back to Finance

The Brief

Priya ShahCFOslack-dm

Board prep. Need gross margin by quarter across 2023-2025. Columns: `year`, `quarter`, `revenue`, `cogs`, `gross_margin` (revenue minus cogs). Use LOWER() on account_type — there's a known casing bug. Posted entries only.

You'll practice

CASEAggregationRatio

Tables available

fact_transactionsdim_accounts

Hints (3)

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

Hint 1

Filter to `LOWER(account_type) IN ('revenue', 'cogs')`.

Hint 2

Use CASE: `SUM(CASE WHEN LOWER(account_type) = 'revenue' THEN amount ELSE 0 END) AS revenue`, same pattern for cogs.

Hint 3

Group by year and quarter: `EXTRACT(YEAR FROM txn_date::date)`, `EXTRACT(QUARTER FROM txn_date::date)`. 3 years × 4 quarters = 12 rows.