Compute Monthly Cohort Retention For Workbook Users
Last updated: November 29, 2026
Quick Overview
Given `users(user_id, signup_at)` and `events(user_id, event_type, event_at)`, write SQL that groups users by signup month and reports the share who viewed or edited a workbook in calendar months 1, 2 and 3 after their signup month.
Sigma Computing
November 29, 20260
0
0 solved
Given `users(user_id, signup_at)` and `events(user_id, event_type, event_at)`, write SQL that groups users by signup month and reports the share who viewed or edited a workbook in calendar months 1, 2 and 3 after their signup month.
Sigma sells seats to business users, so whether new users keep coming back to workbooks drives expansion and renewal. The interviewer checks cohort definition, a correct month offset, distinct counting, and handling cohorts that are too young to measure.
What the Interviewer Expects
- Define cohort month and month offset precisely (calendar months, month 0 is signup month)
- Filter to the events that mean real usage, not logins
- Deduplicate to one row per user per month offset before counting
- Keep users with no activity in the denominator via a LEFT JOIN
- Avoid reporting 0% for months that have not happened yet
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you switch to rolling 30-day windows from signup instead of calendar months?
- How would you compute retention at the org level, which matters more for a B2B renewal?
- How would you show this as a triangle in a Sigma pivot table?
- What would you check if month 1 retention suddenly jumped for one cohort?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Active means an event of type workbook_view or workbook_edit; logins alone do not count. Month offset is the difference in calendar months between the event's month and the signup month, so a Janu...
Approach
cohort: user andDATE_TRUNC('month', signup_at).activity: distinct(user_id, month_n)from qualifying events.- LEFT JOIN cohorts to activity, then count distinct users with `month_n =...