RevOps & Sales Analytics Path · Mission 7 of 30Easy

Deals by close quarter

DATE_TRUNC for time-bucketed aggregation — the foundation of every period-over-period report

The Brief

Hannah LiuFP&A Partner to Salesfinance-sales

I'm building the quarterly bookings dashboard and need the deal count by close quarter. Truncate `close_date` to the start of its quarter, group by that, count opportunities. Return the quarter start date and the count. Order by quarter ascending. Include every stage — open, won, lost — the dashboard filters by stage downstream, but the data-layer query gives the full picture.

You'll practice

DATE_TRUNCGROUP BY

Tables & columns available

revops_opportunitiesfact10 columns
ColumnTypeKey
opportunity_idINTPK
account_idINTFK → revops_accounts
owner_user_idINTFK → revops_users
nameTEXT
stageTEXT
amountREAL
close_dateTEXT
created_dateTEXT
is_closedINT
is_wonINT

Hints (3)

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

Hint 1

Postgres/SQLite-portable: `DATE_TRUNC('quarter', close_date::date)` (casting TEXT to date first). SQLite alternative: `strftime('%Y-', close_date) || printf('%02d', ((CAST(strftime('%m', close_date) AS INTEGER) - 1) / 3) * 3 + 1) || '-01'` — hairy. The Postgres form is cleaner; our backend is Postgres (Supabase).

Hint 2

Group by the truncated expression. `COUNT(*)` as the metric.

Hint 3

You should see exactly 5 quarters — 2024-Q4 through 2025-Q4 — covering every close_date in the seed.