From e320a64166444a40de15015f4a2f67278058612e Mon Sep 17 00:00:00 2001 From: David Young Date: Mon, 30 Nov 2026 13:06:04 -0700 Subject: [PATCH] Metrics: the first month counted is labelled as the existing customers With a "Count from" month set, that month's cohort is everyone already paying then, not only those new that month. Both cohort tables now say "existing customers" under it, the help text explains, and both cohort CSVs add an existing_customers column. Co-Authored-By: Claude Opus 5.5 --- internal/metrics/clv.go | 3 ++- internal/metrics/export.go | 4 ++++ internal/metrics/mrr.go | 7 ++++++- internal/metrics/mrr_test.go | 7 ++++++- internal/web/templates/metrics-clv.html | 2 +- internal/web/templates/metrics.html | 4 ++-- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/internal/metrics/clv.go b/internal/metrics/clv.go index 259d6eb..c72ac9c 100644 --- a/internal/metrics/clv.go +++ b/internal/metrics/clv.go @@ -172,6 +172,7 @@ type Cell struct { // customer, k months after their first paid month. type CohortRevenue struct { Month string + Existing bool // the base: customers already paying when counting starts Customers int PerCustomer []Cell // cents, cumulative, for months 0, 1, 2… Margin []Cell // the same, after gross margin @@ -221,7 +222,7 @@ func RevenueByCohort(d *db.DB, m *Model, n, span int, now time.Time) ([]CohortRe if len(cs) == 0 { continue } - co := CohortRevenue{Month: m.Months[i].Month, Customers: len(cs)} + co := CohortRevenue{Month: m.Months[i].Month, Existing: m.Months[i].Month == m.Base, Customers: len(cs)} var cum float64 for k := 0; k <= span; k++ { if i+k >= len(m.Months) { diff --git a/internal/metrics/export.go b/internal/metrics/export.go index d48829c..39848e4 100644 --- a/internal/metrics/export.go +++ b/internal/metrics/export.go @@ -68,6 +68,7 @@ func Export(w io.Writer, d *db.DB, name string, now time.Time) error { for k := 0; k <= span; k++ { head = append(head, fmt.Sprintf("month_%d_mrr", k)) } + head = append(head, "existing_customers") write(head) for _, c := range model.Cohorts(len(model.Months), span) { row := []string{c.Month, strconv.Itoa(c.Customers), dollars(c.Start)} @@ -81,6 +82,7 @@ func Export(w io.Writer, d *db.DB, name string, now time.Time) error { row = append(row, dollars(v)) } } + row = append(row, strconv.FormatBool(c.Existing)) if err := write(row); err != nil { return err } @@ -95,6 +97,7 @@ func Export(w io.Writer, d *db.DB, name string, now time.Time) error { for k := 0; k <= span; k++ { head = append(head, fmt.Sprintf("month_%d_revenue_per_customer", k)) } + head = append(head, "existing_customers") write(head) for _, c := range cs { row := []string{c.Month, strconv.Itoa(c.Customers)} @@ -105,6 +108,7 @@ func Export(w io.Writer, d *db.DB, name string, now time.Time) error { row = append(row, "") } } + row = append(row, strconv.FormatBool(c.Existing)) if err := write(row); err != nil { return err } diff --git a/internal/metrics/mrr.go b/internal/metrics/mrr.go index e0f2e2c..05b6e78 100644 --- a/internal/metrics/mrr.go +++ b/internal/metrics/mrr.go @@ -166,6 +166,7 @@ type Model struct { First map[string]string // customer → the month they first paid (from Start): their cohort Existing map[string]string // customer → the month first seen paying, for those already customers then (a renewal): no cohort Start string // the first month counted ("" for all) + Base string // the month whose cohort is the customers already paying when counting starts; "" if none Suggest *Suggestion // a start month worth considering, when none is set } @@ -244,6 +245,9 @@ func Build(d *db.DB, now time.Time) (*Model, error) { month = s } startMonth := month.Format("2006-01") + if m.Start != "" { + m.Base = startMonth + } var prev map[string]float64 ever := map[string]bool{} for !month.After(now) { @@ -360,6 +364,7 @@ func (m *Model) Recent(n int) []Month { // starting MRR (net revenue retention by cohort). type Cohort struct { Month string + Existing bool // the base: customers already paying when counting starts, not new that month Customers int Start float64 // their MRR in their first month Retained []float64 // percent of Start, for month 0, 1, 2…; -1 beyond today @@ -384,7 +389,7 @@ func (m *Model) Cohorts(n, span int) []Cohort { if len(cs) == 0 { continue } - co := Cohort{Month: mo.Month, Customers: len(cs)} + co := Cohort{Month: mo.Month, Existing: mo.Month == m.Base, Customers: len(cs)} for _, c := range cs { co.Start += mo.ByCustomer[c] } diff --git a/internal/metrics/mrr_test.go b/internal/metrics/mrr_test.go index f85ff3f..4456a4b 100644 --- a/internal/metrics/mrr_test.go +++ b/internal/metrics/mrr_test.go @@ -141,6 +141,11 @@ func TestStartMonthAndSuggestion(t *testing.T) { if m.Suggest == nil || m.Suggest.Month != "2025-01" || m.Suggest.Customers != 25 { t.Fatalf("suggestion: %+v", m.Suggest) } + for _, co := range m.Cohorts(5, 2) { + if co.Existing { + t.Errorf("no start month set, yet %s is the existing customers", co.Month) + } + } if err := SetStartMonth(d, "2025-01"); err != nil { t.Fatal(err) } @@ -152,7 +157,7 @@ func TestStartMonthAndSuggestion(t *testing.T) { if jan.Month != "2025-01" || jan.New != 0 || jan.Customers != 25 || m.Suggest != nil { t.Errorf("counted from January: %+v", jan) } - if cos := m.Cohorts(5, 2); len(cos) != 1 || cos[0].Customers != 25 { + if cos := m.Cohorts(5, 2); len(cos) != 1 || cos[0].Customers != 25 || !cos[0].Existing { t.Errorf("the starting base's cohort: %+v", cos) } } diff --git a/internal/web/templates/metrics-clv.html b/internal/web/templates/metrics-clv.html index 6813764..afc8ce1 100644 --- a/internal/web/templates/metrics-clv.html +++ b/internal/web/templates/metrics-clv.html @@ -29,7 +29,7 @@
{{range $i, $_ := .Span}}{{end}} - {{range .Cohorts}} + {{range .Cohorts}} {{if $d.Profit}}{{range .Margin}}{{end}}{{else}}{{range .PerCustomer}}{{end}}{{end}} {{end}}
First paidCustomers{{$i}}
{{.Month}}{{.Customers}}
{{.Month}}{{if .Existing}} existing customers{{end}}{{.Customers}}{{if .Known}}{{usd .V}}{{end}}{{if .Known}}{{usd .V}}{{end}}
diff --git a/internal/web/templates/metrics.html b/internal/web/templates/metrics.html index 646280d..6d8632d 100644 --- a/internal/web/templates/metrics.html +++ b/internal/web/templates/metrics.html @@ -62,11 +62,11 @@ {{if $d.Cohorts}}

Cohorts

-

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.

+

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. The first month counted holds the existing customers: everyone already paying then, not only those new that month.

{{range $i, $_ := $d.Span}}{{end}} {{range $d.Cohorts}} - {{range .Retained}}{{end}} + {{range .Retained}}{{end}}{{range .MRR}}{{end}}{{end}}
First paidCustomersStarting MRR{{$i}}
{{.Month}}{{.Customers}}{{usd .Start}}{{if ge . 0.0}}{{pct .}}{{end}}
{{.Month}}{{if .Existing}}
existing customers{{end}}
{{.Customers}}{{usd .Start}}{{if ge . 0.0}}{{pct .}}{{end}}
{{if ge . 0.0}}{{usd .}}{{end}}