Metrics: MRR and cohorts count only paid invoices

Open (unpaid) invoices no longer count toward MRR, so they don't put a
customer in a cohort either; an invoice counts once it's paid. This
matches the customer count, which takes only those who have spent more
than $0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 12:47:30 -07:00
co-authored by Claude Opus 5.5
parent 739f85fde1
commit fab349d166
3 changed files with 7 additions and 5 deletions
+3 -3
View File
@@ -46,11 +46,11 @@ func (l line) monthly() float64 {
return float64(l.amount) / months
}
// loadLines reads the recurring lines of billed invoices (paid or open; not
// void, not uncollectible) in the main currency.
// loadLines reads the recurring lines of paid invoices (not open, void or
// uncollectible) in the main currency.
func loadLines(d *db.DB, currency string) ([]line, error) {
rows, err := d.Query(`SELECT customer, amount, period_start, period_end, interval, interval_count, proration, product
FROM stripe_invoice_lines WHERE recurring = 1 AND status IN ('paid', 'open') AND currency = ? AND customer != ''
FROM stripe_invoice_lines WHERE recurring = 1 AND status = 'paid' AND currency = ? AND customer != ''
AND period_end > period_start ORDER BY invoice, id`, currency) // a fixed order: float sums come out the same everywhere
if err != nil {
return nil, err
+3 -1
View File
@@ -67,8 +67,10 @@ func TestBuild(t *testing.T) {
ln{cust: "cus_a", from: "2026-04-25", to: "2026-05-10", amount: -2500, proration: true},
ln{cust: "cus_a", from: "2026-04-25", to: "2026-05-10", amount: 4000, proration: true})
d.Exec(`UPDATE stripe_invoice_lines SET amount = 8000 WHERE customer = 'cus_a' AND period_start >= ?`, day("2026-05-10"))
// A trial, a void invoice and an uncollectible one count for nothing.
// A trial, an unpaid (open) invoice, a void one and an uncollectible
// one count for nothing.
addLines(t, d, ln{cust: "cus_t", from: "2026-03-01", to: "2026-04-01", interval: "month", amount: 0},
ln{cust: "cus_o", from: "2026-03-01", to: "2026-04-01", interval: "month", amount: 9900, status: "open"},
ln{cust: "cus_v", from: "2026-03-01", to: "2026-04-01", interval: "month", amount: 9900, status: "void"},
ln{cust: "cus_u", from: "2026-03-01", to: "2026-04-01", interval: "month", amount: 9900, status: "uncollectible"})
+1 -1
View File
@@ -40,7 +40,7 @@
{{range .}}<rect x="{{.X}}" y="{{.Y}}" width="{{.W}}" height="{{.H}}"><title>{{.Month}}: {{usd .MRR}}</title></rect>{{if .Label}}<text x="{{.X}}" y="166">{{.Month}}</text>{{end}}{{end}}
</svg>
{{end}}
<p class="small muted">From the invoice lines of paid and open invoices, in {{$d.Model.Currency}}: each recurring line's amount after discounts, spread over its billing period. Trials ($0), one-off charges, void and uncollectible invoices don't count.{{with $d.Model.Start}}{{if ne . "all"}} Counted from {{.}}.{{end}}{{end}}</p>
<p class="small muted">From the invoice lines of paid invoices (an unpaid one counts once it's paid), in {{$d.Model.Currency}}: each recurring line's amount after discounts, spread over its billing period. Trials ($0), one-off charges, void and uncollectible invoices don't count.{{with $d.Model.Start}}{{if ne . "all"}} Counted from {{.}}.{{end}}{{end}}</p>
</section>
<h2>Month by month</h2>