# Cohort and Retention Analysis

> Grouping users by when they started and tracking how many come back, the core way to tell if a product keeps its customers. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/data-analyst/cohort-retention
Last updated: 2026-11-28

Grouping users by when they started and tracking how many come back, the core way to tell if a product keeps its customers.

Intermediate · about 6 hours · difficulty 3/5

Learn first: [Funnel Analysis](https://www.internhack.in/roadmaps/tracks/data-analyst/funnel-analysis), [Dates, Times and Text in SQL](https://www.internhack.in/roadmaps/tracks/data-analyst/sql-dates-strings)

Growth hides problems: total active users can rise while each new group of customers leaves faster. **Cohort analysis** separates users by their start date so you can see whether retention is improving.

### The retention table

- Rows are **cohorts** (users grouped by signup week or first purchase month).
- Columns are **periods since start** (week 0, week 1, week 2...).
- Cells are the percentage of the cohort active in that period.

Reading down a column shows whether newer cohorts retain better; reading across a row shows how one cohort decays.

### Building it in SQL

1. Find each user's cohort: `MIN(activity_date)` truncated to week or month.
2. Join activity back and compute the period number: `DATE_DIFF` between activity and cohort start.
3. Count distinct users per cohort and period, then divide by the cohort size (period 0).

### Retention definitions

- **N-day (classic) retention**: active exactly on day N.
- **Unbounded (rolling) retention**: active on day N or later.
- **Bracket retention**: active within a range like days 7-13.

Pick one and say which; they give very different numbers.

### Related metrics

- **Churn rate**: share of customers lost in a period (for subscriptions, cancellations divided by customers at the start).
- **Retention curve flattening**: a curve that levels off means you have found a loyal core; one that trends to zero is a warning.
- **Stickiness**: DAU / MAU.

**Pitfall:** averaging retention across cohorts of very different sizes without weighting. You are ready to move on when you can build a monthly cohort retention heatmap from raw events and describe what it shows.

## Key concepts

- **Defining cohorts**
- **Retention tables and heatmaps**
- **Cohort queries in SQL**
- **N-day vs unbounded retention**
- **Churn rate**
- **DAU, WAU, MAU and stickiness**
- **Retention curves and flattening**
- **Survival analysis**: Time-to-churn models

## Mini project

Using the UCI Online Retail dataset, build a monthly first-purchase cohort retention heatmap in SQL or pandas and write three observations about it.

## Check yourself

Total monthly active users grew 30% this year. What would a cohort chart need to show for that to be bad news?

## Free resources

- [Amplitude docs: retention analysis](https://amplitude.com/docs/analytics/charts/retention-analysis/retention-analysis-build) (Amplitude)
- [Mode SQL Tutorial](https://mode.com/sql-tutorial) (Mode)
- [Cohort analysis (overview)](https://en.wikipedia.org/wiki/Cohort_analysis) (Wikipedia)

Previous: [Funnel Analysis](https://www.internhack.in/roadmaps/tracks/data-analyst/funnel-analysis) · Next: [Unit Economics and Revenue Metrics](https://www.internhack.in/roadmaps/tracks/data-analyst/unit-economics)

## More in Business and Product Metrics

- [KPIs and Metric Design](https://www.internhack.in/roadmaps/tracks/data-analyst/kpi-design)
- [Funnel Analysis](https://www.internhack.in/roadmaps/tracks/data-analyst/funnel-analysis)
- [Cohort and Retention Analysis](https://www.internhack.in/roadmaps/tracks/data-analyst/cohort-retention)
- [Unit Economics and Revenue Metrics](https://www.internhack.in/roadmaps/tracks/data-analyst/unit-economics)
- [Diagnosing Metric Changes](https://www.internhack.in/roadmaps/tracks/data-analyst/metric-diagnosis)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Data Analyst Roadmap](https://www.internhack.in/roadmaps/tracks/data-analyst)
