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
Data Manipulation (SQL/Python)
Data Scientist
Sigma Computing
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

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
cohort analysis
retention
DATEDIFF
LEFT JOIN
conditional aggregation
B2B metrics
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. 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 Problems
Sample 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
  1. cohort: user and DATE_TRUNC('month', signup_at).
  2. activity: distinct (user_id, month_n) from qualifying events.
  3. LEFT JOIN cohorts to activity, then count distinct users with `month_n =...

Submit Your Answer
Markdown supported

Related Questions