diff --git a/internal/metrics/export.go b/internal/metrics/export.go index ac04b71..6eca530 100644 --- a/internal/metrics/export.go +++ b/internal/metrics/export.go @@ -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 } diff --git a/internal/metrics/mrr.go b/internal/metrics/mrr.go index 3e1ac30..e0f2e2c 100644 --- a/internal/metrics/mrr.go +++ b/internal/metrics/mrr.go @@ -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) } diff --git a/internal/metrics/mrr_test.go b/internal/metrics/mrr_test.go index 2a093e8..f85ff3f 100644 --- a/internal/metrics/mrr_test.go +++ b/internal/metrics/mrr_test.go @@ -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) diff --git a/internal/web/templates/metrics.html b/internal/web/templates/metrics.html index 25f4ca1..f2ce922 100644 --- a/internal/web/templates/metrics.html +++ b/internal/web/templates/metrics.html @@ -62,10 +62,10 @@ {{if $d.Cohorts}}

Cohorts

-

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.

+

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.

{{range $i, $_ := $d.Span}}{{end}} - {{range $d.Cohorts}}{{range .Retained}}{{end}}{{end}} + {{range $d.Cohorts}}{{$co := .}}{{range $k, $r := .Retained}}{{end}}{{end}}
First paidCustomersStarting MRR{{$i}}
{{.Month}}{{.Customers}}{{usd .Start}}{{if ge . 0.0}}{{pct .}}{{end}}
{{.Month}}{{.Customers}}{{usd .Start}}{{if ge $r 0.0}}{{pct $r}}
{{usd (index $co.MRR $k)}}{{end}}

Download as CSV (every cohort, 24 months)

{{end}}