Month-over-month growth
HardLAG and growth ratesSaaS / product
The problem
For each region and month, show region, month, revenue and mom_growth_pct: the percentage change from the same region's previous month, rounded to 1 decimal place.
The first month of each region has no previous month, so mom_growth_pct should be NULL. Sort by region, then month.
Learn this in the course: Window functions (video and notes)
Tables · Product usage and revenue
Click a table or column name to insert it into your query.
- INTEGER · primary key
- INTEGER
- TEXT · visit | signup | purchase
- DATE
Sample rows (24 total)
| event_id | user_id | event_type | event_date |
|---|---|---|---|
| 1 | 1 | visit | 2025-06-01 |
| 2 | 2 | visit | 2025-06-01 |
| 3 | 3 | visit | 2025-06-01 |
| 4 | 4 | visit | 2025-06-02 |
| 5 | 5 | visit | 2025-06-02 |
- TEXT · YYYY-MM
- TEXT
- INTEGER · rupees
Sample rows (10 total)
| month | region | revenue |
|---|---|---|
| 2025-01 | North | 100000 |
| 2025-02 | North | 110000 |
| 2025-03 | North | 105000 |
| 2025-04 | North | 120000 |
| 2025-05 | North | 130000 |
Ctrl/⌘ + Enter runs the query. Table and column names are suggested as you type. Press Esc then Tab to leave the editor with the keyboard.
Expected output (10 rows)
| region | month | revenue | mom_growth_pct |
|---|---|---|---|
| North | 2025-01 | 100000 | NULL |
| North | 2025-02 | 110000 | 10.0 |
| North | 2025-03 | 105000 | -4.5 |
| North | 2025-04 | 120000 | 14.3 |
| North | 2025-05 | 130000 | 8.3 |
| South | 2025-01 | 80000 | NULL |
| South | 2025-02 | 85500 | 6.9 |
| South | 2025-03 | 90000 | 5.3 |
| South | 2025-04 | 88000 | -2.2 |
| South | 2025-05 | 95000 | 8.0 |
Row order matters for this question. Numbers are compared with a tiny tolerance; text must match exactly.
Stuck?
Stored on this device only. Your latest query and “solved” status are remembered in this browser only. They don’t sync between devices, and clearing your browser data removes them.