Pharma Commercial Analytics Path · Mission 8 of 25Medium

Quarterly call volume trend

Date-string slicing with substr() to roll fact_calls up to quarterly buckets. Pharma stores dates as YYYY-MM-DD TEXT; carving out year + quarter is the most common reporting transform. Single-table aggregate with a derived column — a Medium step up from M4's flat per-rep count.

The Brief

Hannah ReedSales Operations Managerslack-dm

Marcus wants the field-force activity trend for the QBR deck. From fact_calls, give me total call counts rolled to the quarter — output 'YYYY-Qn' format (e.g. '2025-Q3'), sorted ascending so the trend line reads left-to-right. Two columns: quarter, calls. Use substr() to slice the call_date string; the math for 'which quarter' is (month + 2) / 3, integer division. The 24-month window has 9 quarters; expect 2024-Q2 through 2026-Q2.

You'll practice

substr dateGROUP BY derived expressionCOUNT(*)

Tables & columns available

fact_callsfact7 columns
ColumnTypeKey
call_idINTPK
hcp_npiTEXTFK → dim_hcp
rep_idINTFK → dim_rep
product_idINTFK → dim_product
call_dateTEXT
duration_minINT
samples_droppedINT

Hints (3)

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

Hint 1

substr(call_date, 1, 4) extracts the year (positions 1-4); substr(call_date, 6, 2) extracts the month (positions 6-7). Both come back as TEXT — cast the month to INTEGER before doing math on it.

Hint 2

Quarter math is integer division on the month number — once you have month as an INTEGER, you can map (month → 1/2/3/4) with a single arithmetic expression. Concat with the year via || and a literal '-Q' separator to get the '2025-Q3' shape.

Hint 3

GROUP BY the derived quarter expression. COUNT(*) AS calls. ORDER BY quarter ASC so the trend reads left-to-right.