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 <noreply@anthropic.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user