Sub topic 10
Cohort Analysis and Retention Tables
This chapter assumes you understand basic percentages, ratios, and simple charts. It also assumes basic SQL, including SELECT, JOIN, and GROUP BY.
What a cohort is
A cohort is a group of users who share a starting condition. In product analysis, the condition is often the week or month when users signed up. For example, the January 5 signup cohort contains every user who signed up during the week beginning January 5.
Cohort analysis compares groups that started at different times. This prevents newer users from being judged against users who have had more time to use the product.
A retention table shows how much of each cohort returns to perform a meaningful action:
| Signup cohort | Week 0 | Week 1 | Week 2 | Week 3 |
|---|---|---|---|---|
| January 5 | 100% | 42% | 31% | 24% |
| January 12 | 100% | 38% | 27% | 21% |
| January 19 | 100% | 45% | 34% | — |
Each row is a cohort. Each column is the number of weeks since signup. Week 0 usually represents the starting period. A dash means the cohort has not existed long enough to produce that measurement. It is not the same as zero retention.
The denominator for each row is the original cohort size. If 100 users signed up in a week and 42 performed the core action during the next week, Week 1 retention is 42%.
Build the table from events
The analysis needs three pieces of data:
- A stable
user_id - Each user's signup time
- Events that identify the product's meaningful core action
The following query creates one row for each cohort and retention week. It uses PostgreSQL syntax.
-- Weekly cohort retention: share of each signup-week cohort
-- active in each later week
WITH cohorts AS (
SELECT
user_id,
DATE_TRUNC('week', signup_at) AS cohort_week
FROM users
),
cohort_sizes AS (
SELECT
cohort_week,
COUNT(*) AS size
FROM cohorts
GROUP BY cohort_week
),
activity AS (
SELECT DISTINCT
user_id,
DATE_TRUNC('week', event_time) AS active_week
FROM events
WHERE event_name = 'core_action'
)
SELECT
c.cohort_week,
(a.active_week::date - c.cohort_week::date) / 7 AS week_number,
COUNT(DISTINCT a.user_id) * 1.0 / s.size AS retention
FROM cohorts AS c
JOIN activity AS a
ON a.user_id = c.user_id
AND a.active_week >= c.cohort_week
JOIN cohort_sizes AS s
ON s.cohort_week = c.cohort_week
GROUP BY
c.cohort_week,
week_number,
s.size
ORDER BY
c.cohort_week,
week_number;DISTINCT prevents multiple events from counting the same user more than once in a week. The query joins activity to the user's own signup cohort, rather than using one global date range.
Interpret retention patterns
A steep drop between Week 0 and Week 1 may mean users do not reach value quickly, or that the chosen core action is too strict. A flatter curve after the first weeks suggests that the remaining users have formed a stable usage pattern.
Compare cohorts by the same age. Do not compare a three-week-old cohort's Week 3 value with a six-month-old cohort's current total. Also check whether tracking, pricing, onboarding, or product behavior changed between cohorts. A retention difference is useful evidence, but it does not by itself explain the cause.
Exercise
A signup cohort contains 80 users. In its second week, 20 distinct users perform the core action. What is Week 1 retention, and what must you check before comparing it with another cohort?
Show answer
Week 1 retention is 20 ÷ 80 = 25%. Check that both cohorts use the same signup definition, core action, time zone, and week boundaries, and that both Week 1 periods are complete.