Sub topic 10
Cohort analysis and retention tables
This chapter assumes you can read basic SQL (SELECT, JOIN, GROUP BY) and that you know how to define a metric by population, event, and time window. It also assumes you know what a "core action" is, meaning the one event that shows a user got value from the product. Here you will build a cohort retention table and learn to read it.
What a cohort is and why it beats a single average
A cohort is a group of users who share a starting event in the same time period. The most common cohort is a signup cohort, such as "everyone who signed up in the week of 2026-01-05".
A single retention number for all users mixes old and new users. If your product improved in February, the blended number hides it behind years of older behavior. Cohorts hold the starting point constant, so you can compare like with like.
Cohort analysis answers three questions:
- How much of a group is still active after N periods?
- Does a newer group behave better or worse than an older one?
- At what point does the loss of users slow down or stop?
The shape of a retention table
A retention table has one row per cohort and one column per period since the start. Each cell is the share of that cohort that performed the core action in that period.
| Cohort (signup week) | Size | Week 0 | Week 1 | Week 2 | Week 3 |
|---|---|---|---|---|---|
| 2026-01-05 | 1,000 | 100% | 38% | 29% | 25% |
| 2026-01-12 | 1,100 | 100% | 41% | 32% | 28% |
| 2026-01-19 | 950 | 100% | 45% | 35% | |
| 2026-01-26 | 1,200 | 100% | 47% |
Three things to notice:
- Reading across a row shows how one cohort decays over time.
- Reading down a column compares cohorts at the same age. Week 1 retention rises from 38% to 47%, which suggests something improved.
- The empty cells in the lower right are not zeros. They are periods that have not happened yet. The table has a triangular shape for this reason.
Choosing the cohort and period
Two choices shape the table. Both should be written down as part of the metric definition.
- Cohort grain. Daily cohorts are noisy for small products. Weekly cohorts suit most products. Monthly cohorts suit products with long usage cycles, such as accounting software.
- Period grain. The period should match how often a healthy user is expected to return. A meditation app used daily can use day-based periods. A tax tool used once a year cannot be judged on weekly retention.
Cohorts can also start from an event other than signup, such as first purchase or activation. An activation-based cohort removes users who never reached value, which makes retention easier to interpret. It also hides the activation problem, so report activation separately.
Building the table in SQL
The query below builds one row per cohort and week number. It assumes users(user_id, signup_at) and events(user_id, event_name, event_time), and it is written for PostgreSQL.
-- 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 c
JOIN activity a
ON a.user_id = c.user_id
AND a.active_week >= c.cohort_week
JOIN cohort_sizes s
ON s.cohort_week = c.cohort_week
GROUP BY c.cohort_week, week_number, s.size
ORDER BY c.cohort_week, week_number;How each part works:
cohortsassigns every user to the Monday of their signup week.cohort_sizescounts the denominator once per cohort. It uses all users in the cohort, not only those who were later active.activityreduces events to one row per user per active week. TheDISTINCTkeeps a user with fifty events from being counted fifty times.- The join keeps only activity on or after the cohort week, then computes how many weeks later it happened.
- Dividing distinct active users by cohort size gives the retention for each cell.
Gotchas in this query
- Inner join drops empty periods. A week in which nobody from a cohort was active produces no row, not a row with 0%. When you pivot the result, cells with no row may be shown as blank when they are really zero. Generate a calendar of weeks and left join if you need an exact zero.
- Incomplete current week. The latest week is partial, so its retention is understated. Exclude it or label it clearly.
- Week boundaries.
DATE_TRUNC('week', ...)starts weeks on Monday in PostgreSQL. A user who signs up on Sunday night and returns on Monday is counted as Week 1 even though the gap is one day. Calendar weeks are simple but blur the exact gap. If this matters, use days since each user's own signup instead. - Week 0 is not always 100%. It is 100% only if the cohort is defined by the core action itself. With signup cohorts, Week 0 shows how many users did the core action in their first week, which is close to an activation rate.
- Time zones. Truncate in one consistent time zone, or users near midnight will move between cohorts.
- Identity. If one person has two
user_idvalues, they appear in two cohorts and inflate the cohort size.
Reading the table
Read in a fixed order so that you do not chase noise.
- Check cohort sizes. A cohort of 40 users can swing 10 points on a few people. Treat small rows with caution.
- Read the first period. The drop from Week 0 to Week 1 is usually the steepest and often points to onboarding problems.
- Look for a flattening. If a row levels off at, say, 25%, that group has a stable core of users. If it keeps falling toward zero, the product has not found lasting value for them.
- Compare down the columns. A change that starts at one cohort and continues in later cohorts suggests a real product or channel change. A single odd row suggests a one-off event such as a promotion.
- Look for diagonal patterns. A dip that runs along a diagonal affects several cohorts in the same calendar week. That points to an outside cause, such as an outage or a holiday, and not to cohort quality.
Common mistakes
- Dividing by active users instead of cohort size. The denominator must be everyone who started in the cohort. Dividing by those still active produces a number that always looks healthy.
- Mixing definitions across rows. If the core action changed in March, older and newer cohorts are no longer comparable. Record the date of any definition change.
- Treating the blended average as the result. Averaging all cohorts weights old, large cohorts heavily. Show the rows.
- Judging a cohort before it matures. Compare cohorts only at ages that all of them have reached.
- Ignoring segments. A flat overall table can hide one segment improving while another worsens. Splitting cohorts by acquisition channel or plan is covered in a later chapter.
Exercise
A cohort of 500 users signed up in the week of 2026-02-02. In Week 2, 120 distinct users from that cohort performed the core action, and 150 events came from users who had signed up in other weeks. What is the Week 2 retention for this cohort, and why do the other 150 events not matter?
Show answer
Retention is 120 / 500 = 24%. The numerator counts only distinct users from this cohort who were active in Week 2, and the denominator is the full cohort size. Events from users in other cohorts belong to those cohorts' rows, and repeated events from the same user count only once.
Exercise
A table shows 0% in the Week 4 cell for the cohort that signed up two weeks ago. Is this a retention problem? What should the cell show?
Show answer
No. Week 4 has not happened yet for that cohort, so the value is unknown. The cell should be empty or marked as not available, not 0%.