Finance Data Analyst Path · Mission 10 of 30Easy

Quarterly gross-margin rollup

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

Back to Finance Data Analyst

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 & columns available

fact_transactionsfact10 columns
ColumnTypeKey
txn_idINTPK
txn_dateTEXT
account_idINTFK → dim_accounts
cost_center_idINTFK → dim_cost_centers
vendor_idINTFK → dim_vendors
amountREAL
currencyTEXT
descriptionTEXT
postedINT
posted_dateTEXT
dim_accountsdim5 columns
ColumnTypeKey
account_idINTPK
account_codeTEXT
account_nameTEXT
account_typeTEXT
is_activeINT

Hints (3)

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

Hint 1

Gross margin requires two account types from the same table — but you want them as separate columns in one row per quarter, not as separate rows. Think about how to pivot account types into columns within an aggregation.

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 both year and quarter using EXTRACT on the cast date — one row per period covers your full data range.