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.
|
// customer, k months after their first paid month.
|
||||||
type CohortRevenue struct {
|
type CohortRevenue struct {
|
||||||
Month string
|
Month string
|
||||||
|
Existing bool // the base: customers already paying when counting starts
|
||||||
Customers int
|
Customers int
|
||||||
PerCustomer []Cell // cents, cumulative, for months 0, 1, 2…
|
PerCustomer []Cell // cents, cumulative, for months 0, 1, 2…
|
||||||
Margin []Cell // the same, after gross margin
|
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 {
|
if len(cs) == 0 {
|
||||||
continue
|
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
|
var cum float64
|
||||||
for k := 0; k <= span; k++ {
|
for k := 0; k <= span; k++ {
|
||||||
if i+k >= len(m.Months) {
|
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++ {
|
for k := 0; k <= span; k++ {
|
||||||
head = append(head, fmt.Sprintf("month_%d_mrr", k))
|
head = append(head, fmt.Sprintf("month_%d_mrr", k))
|
||||||
}
|
}
|
||||||
|
head = append(head, "existing_customers")
|
||||||
write(head)
|
write(head)
|
||||||
for _, c := range model.Cohorts(len(model.Months), span) {
|
for _, c := range model.Cohorts(len(model.Months), span) {
|
||||||
row := []string{c.Month, strconv.Itoa(c.Customers), dollars(c.Start)}
|
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, dollars(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
row = append(row, strconv.FormatBool(c.Existing))
|
||||||
if err := write(row); err != nil {
|
if err := write(row); err != nil {
|
||||||
return err
|
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++ {
|
for k := 0; k <= span; k++ {
|
||||||
head = append(head, fmt.Sprintf("month_%d_revenue_per_customer", k))
|
head = append(head, fmt.Sprintf("month_%d_revenue_per_customer", k))
|
||||||
}
|
}
|
||||||
|
head = append(head, "existing_customers")
|
||||||
write(head)
|
write(head)
|
||||||
for _, c := range cs {
|
for _, c := range cs {
|
||||||
row := []string{c.Month, strconv.Itoa(c.Customers)}
|
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, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
row = append(row, strconv.FormatBool(c.Existing))
|
||||||
if err := write(row); err != nil {
|
if err := write(row); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ type Model struct {
|
|||||||
First map[string]string // customer → the month they first paid (from Start): their cohort
|
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
|
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)
|
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
|
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
|
month = s
|
||||||
}
|
}
|
||||||
startMonth := month.Format("2006-01")
|
startMonth := month.Format("2006-01")
|
||||||
|
if m.Start != "" {
|
||||||
|
m.Base = startMonth
|
||||||
|
}
|
||||||
var prev map[string]float64
|
var prev map[string]float64
|
||||||
ever := map[string]bool{}
|
ever := map[string]bool{}
|
||||||
for !month.After(now) {
|
for !month.After(now) {
|
||||||
@@ -360,6 +364,7 @@ func (m *Model) Recent(n int) []Month {
|
|||||||
// starting MRR (net revenue retention by cohort).
|
// starting MRR (net revenue retention by cohort).
|
||||||
type Cohort struct {
|
type Cohort struct {
|
||||||
Month string
|
Month string
|
||||||
|
Existing bool // the base: customers already paying when counting starts, not new that month
|
||||||
Customers int
|
Customers int
|
||||||
Start float64 // their MRR in their first month
|
Start float64 // their MRR in their first month
|
||||||
Retained []float64 // percent of Start, for month 0, 1, 2…; -1 beyond today
|
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 {
|
if len(cs) == 0 {
|
||||||
continue
|
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 {
|
for _, c := range cs {
|
||||||
co.Start += mo.ByCustomer[c]
|
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 {
|
if m.Suggest == nil || m.Suggest.Month != "2025-01" || m.Suggest.Customers != 25 {
|
||||||
t.Fatalf("suggestion: %+v", m.Suggest)
|
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 {
|
if err := SetStartMonth(d, "2025-01"); err != nil {
|
||||||
t.Fatal(err)
|
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 {
|
if jan.Month != "2025-01" || jan.New != 0 || jan.Customers != 25 || m.Suggest != nil {
|
||||||
t.Errorf("counted from January: %+v", jan)
|
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)
|
t.Errorf("the starting base's cohort: %+v", cos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
</nav>
|
</nav>
|
||||||
<div class="table-wrap"><table class="list compact cohorts">
|
<div class="table-wrap"><table class="list compact cohorts">
|
||||||
<thead><tr><th>First paid</th><th class="num">Customers</th>{{range $i, $_ := .Span}}<th class="num">{{$i}}</th>{{end}}</tr></thead>
|
<thead><tr><th>First paid</th><th class="num">Customers</th>{{range $i, $_ := .Span}}<th class="num">{{$i}}</th>{{end}}</tr></thead>
|
||||||
<tbody>{{range .Cohorts}}<tr><td>{{.Month}}</td><td class="num">{{.Customers}}</td>
|
<tbody>{{range .Cohorts}}<tr><td>{{.Month}}{{if .Existing}} <span class="muted small">existing customers</span>{{end}}</td><td class="num">{{.Customers}}</td>
|
||||||
{{if $d.Profit}}{{range .Margin}}<td class="num">{{if .Known}}{{usd .V}}{{end}}</td>{{end}}{{else}}{{range .PerCustomer}}<td class="num">{{if .Known}}{{usd .V}}{{end}}</td>{{end}}{{end}}
|
{{if $d.Profit}}{{range .Margin}}<td class="num">{{if .Known}}{{usd .V}}{{end}}</td>{{end}}{{else}}{{range .PerCustomer}}<td class="num">{{if .Known}}{{usd .V}}{{end}}</td>{{end}}{{end}}
|
||||||
</tr>{{end}}</tbody>
|
</tr>{{end}}</tbody>
|
||||||
</table></div>
|
</table></div>
|
||||||
|
|||||||
@@ -62,11 +62,11 @@
|
|||||||
|
|
||||||
{{if $d.Cohorts}}
|
{{if $d.Cohorts}}
|
||||||
<h2>Cohorts</h2>
|
<h2>Cohorts</h2>
|
||||||
<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>
|
<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. The first month counted holds the existing customers: everyone already paying then, not only those new that month.</p>
|
||||||
<div class="table-wrap"><table class="list compact cohorts">
|
<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>
|
<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>
|
||||||
{{range $d.Cohorts}}<tbody class="cohort">
|
{{range $d.Cohorts}}<tbody class="cohort">
|
||||||
<tr class="pct"><td rowspan="2">{{.Month}}</td><td class="num" rowspan="2">{{.Customers}}</td><td class="num" rowspan="2">{{usd .Start}}</td>{{range .Retained}}<td class="num">{{if ge . 0.0}}{{pct .}}{{end}}</td>{{end}}</tr>
|
<tr class="pct"><td rowspan="2">{{.Month}}{{if .Existing}}<br><span class="muted small">existing customers</span>{{end}}</td><td class="num" rowspan="2">{{.Customers}}</td><td class="num" rowspan="2">{{usd .Start}}</td>{{range .Retained}}<td class="num">{{if ge . 0.0}}{{pct .}}{{end}}</td>{{end}}</tr>
|
||||||
<tr class="usd">{{range .MRR}}<td class="num">{{if ge . 0.0}}{{usd .}}{{end}}</td>{{end}}</tr>
|
<tr class="usd">{{range .MRR}}<td class="num">{{if ge . 0.0}}{{usd .}}{{end}}</td>{{end}}</tr>
|
||||||
</tbody>{{end}}
|
</tbody>{{end}}
|
||||||
</table></div>
|
</table></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user