Search docs

Jump to any table example

Discord—

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
CohortUsers01234567891011
40100%35%23%15%10%8%5%3%3%0%0%0%
610100%39%31%30%26%24%22%21%19%19%19%Not reached yet
720100%41%32%30%26%23%22%21%20%19%Not reached yetNot reached yet
680100%46%34%31%26%24%22%21%21%Not reached yetNot reached yetNot reached yet
820100%46%34%32%27%26%24%23%Not reached yetNot reached yetNot reached yetNot reached yet
900100%46%38%32%26%25%24%Not reached yetNot reached yetNot reached yetNot reached yetNot reached yet
860100%46%35%30%29%26%Not reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yet
940100%47%37%34%30%Not reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yet
1,010100%49%38%32%Not reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yet
980100%47%37%Not reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yet
1,100100%53%Not reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yet
1,240100%Not reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yetNot reached yet
Averageweighted, %9,900100%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.

src/components/cohort-retention/cohorts.ts
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.

src/components/cohort-retention/columns.tsx
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.

src/components/cohort-retention/cohorts.ts
const reached = list.filter((c) => period < c.retained.length)
if (reached.length < 2) return null
percent: (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.

src/components/cohort-retention/index.tsx
toggle={(id) => setHighlighted((h) => (h === id ? null : id))}