Shadcn Cohort Retention Table
Users grouped by the month they signed up, and how many were still active each month after. Switch between counts and percentages, highlight a cohort, and tell months not reached yet from real zeros.
$ npx shadcn add https://www.shad-table.dev/r/cohort-retention-table.json- 0%60%+ retained
- Zero: nobody came back
- Not reached yet
| Months since signup | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Cohort | Users | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 40 | 100% | 35% | 23% | 15% | 10% | 8% | 5% | 3% | 3% | 0% | 0% | 0% | |
| 610 | 100% | 39% | 31% | 30% | 26% | 24% | 22% | 21% | 19% | 19% | 19% | Not reached yet | |
| 720 | 100% | 41% | 32% | 30% | 26% | 23% | 22% | 21% | 20% | 19% | Not reached yet | Not reached yet | |
| 680 | 100% | 46% | 34% | 31% | 26% | 24% | 22% | 21% | 21% | Not reached yet | Not reached yet | Not reached yet | |
| 820 | 100% | 46% | 34% | 32% | 27% | 26% | 24% | 23% | Not reached yet | Not reached yet | Not reached yet | Not reached yet | |
| 900 | 100% | 46% | 38% | 32% | 26% | 25% | 24% | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | |
| 860 | 100% | 46% | 35% | 30% | 29% | 26% | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | |
| 940 | 100% | 47% | 37% | 34% | 30% | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | |
| 1,010 | 100% | 49% | 38% | 32% | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | |
| 980 | 100% | 47% | 37% | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | |
| 1,100 | 100% | 53% | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | |
| 1,240 | 100% | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | Not reached yet | |
| Averageweighted, % | 9,900 | 100% | 46% | 35% | 31% | 27% | 24% | 23% | 21% | 20% | 18% | 18% | Too few cohorts to average |
Pick a cohort to highlight it and compare it with the average.
How it works
1.Missing months are not zeros
Each cohort keeps one number per month it has lived through, and the list simply stops where the cohort has not reached the month yet. Those cells are hatched and read "Not reached yet". A real zero, like the soft-launch cohort losing its last users, is an ordinary cell that says 0%, so the two never look alike.
if (period >= cohort.retained.length) return { kind: 'unavailable' }return { kind: 'value', count, percent: (count / cohort.size) * 100 }
2.One hue, scaled to where the data is
Every cell is a shade of the same blue, mixed with the background by how many users stayed. Retention after the first month sits between 0 and about 50%, so the scale tops out at 60% to keep those differences visible. Text turns white on the strong cells, and every value is printed, so color is never the only way to read it.
backgroundColor: `color-mix(in oklab, var(--cohort) ${intensity(percent) * 100}%, transparent)`
3.Counts or percentages
The toggle switches every cell between users still active and the share of the cohort. The average row stays a percentage, weighted by cohort size and counting only cohorts that reached the month, because counts added across different cohorts mean nothing on their own. A month only one cohort has reached gets no average: one cohort is not an average, and a small one would make it swing.
const reached = list.filter((c) => period < c.retained.length)if (reached.length < 2) return nullpercent: (kept / users) * 100
4.Highlight a cohort
Clicking a cohort keeps its row at full strength and fades the others, and the line under the table compares it with the average at month three. Clicking it again, or the clear button, brings the table back.
toggle={(id) => setHighlighted((h) => (h === id ? null : id))}