Metrics: cohorts show each month's dollars beside the percentage
Each cohort cell now gives what the same customers pay that month, in dollars, under the share of their starting MRR. The cohorts CSV adds month_N_mrr columns after the month_N_pct ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -64,12 +64,22 @@ func Export(w io.Writer, d *db.DB, name string, now time.Time) error {
|
||||
for k := 0; k <= 24; k++ {
|
||||
head = append(head, fmt.Sprintf("month_%d_pct", k))
|
||||
}
|
||||
for k := 0; k <= 24; k++ {
|
||||
head = append(head, fmt.Sprintf("month_%d_mrr", k))
|
||||
}
|
||||
write(head)
|
||||
for _, c := range model.Cohorts(1000, 24) {
|
||||
row := []string{c.Month, strconv.Itoa(c.Customers), dollars(c.Start)}
|
||||
for _, r := range c.Retained {
|
||||
row = append(row, pct(r))
|
||||
}
|
||||
for _, v := range c.MRR {
|
||||
if v < 0 {
|
||||
row = append(row, "")
|
||||
} else {
|
||||
row = append(row, dollars(v))
|
||||
}
|
||||
}
|
||||
if err := write(row); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -355,14 +355,15 @@ func (m *Model) Recent(n int) []Month {
|
||||
return out
|
||||
}
|
||||
|
||||
// Cohort is the customers who first paid in one month, and the share of
|
||||
// their starting MRR they pay in each month after (net revenue retention by
|
||||
// cohort).
|
||||
// Cohort is the customers who first paid in one month, and what those same
|
||||
// customers pay in each month after: in dollars, and as a share of their
|
||||
// starting MRR (net revenue retention by cohort).
|
||||
type Cohort struct {
|
||||
Month string
|
||||
Customers int
|
||||
Start float64 // their MRR in their first month
|
||||
Retained []float64 // percent of Start, for month 0, 1, 2…; -1 beyond today
|
||||
MRR []float64 // their MRR, in cents, for month 0, 1, 2…; -1 beyond today
|
||||
}
|
||||
|
||||
// Cohorts are the last n signup cohorts, newest first, each followed for up
|
||||
@@ -390,6 +391,7 @@ func (m *Model) Cohorts(n, span int) []Cohort {
|
||||
for k := 0; k <= span; k++ {
|
||||
if i+k >= len(m.Months) || co.Start == 0 {
|
||||
co.Retained = append(co.Retained, -1)
|
||||
co.MRR = append(co.MRR, -1)
|
||||
continue
|
||||
}
|
||||
kept := 0.0
|
||||
@@ -397,6 +399,7 @@ func (m *Model) Cohorts(n, span int) []Cohort {
|
||||
kept += m.Months[i+k].ByCustomer[c]
|
||||
}
|
||||
co.Retained = append(co.Retained, 100*kept/co.Start)
|
||||
co.MRR = append(co.MRR, kept)
|
||||
}
|
||||
out = append(out, co)
|
||||
}
|
||||
|
||||
@@ -120,6 +120,10 @@ func TestBuild(t *testing.T) {
|
||||
if len(cos) != 3 || cos[0].Month != "2026-03" || cos[2].Month != "2026-01" || cos[2].Retained[0] != 100 || !near(cos[2].Retained[3], 100*(5000+3044)/5000) {
|
||||
t.Errorf("cohorts: %+v", cos)
|
||||
}
|
||||
// The same customers' dollars, month by month; none beyond today.
|
||||
if !near(cos[2].MRR[0], 5000) || !near(cos[2].MRR[3], 5000+3044) || m.Cohorts(1, 4)[0].MRR[4] != -1 {
|
||||
t.Errorf("cohort MRR: %v, %v", cos[2].MRR, cos[0].MRR)
|
||||
}
|
||||
ch := m.Changes("2026-04", map[string]Customer{"cus_b": {ID: "cus_b", Name: "Bea"}})
|
||||
if len(ch) != 2 || ch[0].Customer.Name != "" || ch[1].Customer.Name != "Bea" || ch[1].Kind != MoveChurn {
|
||||
t.Errorf("changes: %+v", ch)
|
||||
|
||||
@@ -62,10 +62,10 @@
|
||||
|
||||
{{if $d.Cohorts}}
|
||||
<h2>Cohorts</h2>
|
||||
<p class="help">Customers by the month they first paid, and the share of their first month's MRR they pay each month after: above 100% means they grew.</p>
|
||||
<p class="help">Customers by the month they first paid, and what those same customers pay each month after: the share of their starting MRR (above 100% means they grew), and below it the dollars.</p>
|
||||
<div class="table-wrap"><table class="list compact cohorts">
|
||||
<thead><tr><th>First paid</th><th class="num">Customers</th><th class="num">Starting MRR</th>{{range $i, $_ := $d.Span}}<th class="num">{{$i}}</th>{{end}}</tr></thead>
|
||||
<tbody>{{range $d.Cohorts}}<tr><td>{{.Month}}</td><td class="num">{{.Customers}}</td><td class="num">{{usd .Start}}</td>{{range .Retained}}<td class="num">{{if ge . 0.0}}{{pct .}}{{end}}</td>{{end}}</tr>{{end}}</tbody>
|
||||
<tbody>{{range $d.Cohorts}}<tr><td>{{.Month}}</td><td class="num">{{.Customers}}</td><td class="num">{{usd .Start}}</td>{{$co := .}}{{range $k, $r := .Retained}}<td class="num">{{if ge $r 0.0}}{{pct $r}}<br><span class="muted small">{{usd (index $co.MRR $k)}}</span>{{end}}</td>{{end}}</tr>{{end}}</tbody>
|
||||
</table></div>
|
||||
<p class="small"><a href="/metrics/export/nrr-cohorts.csv">Download as CSV</a> (every cohort, 24 months)</p>
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user