SQL Dojo
Metric

Churn rate and net revenue retention (NRR)

Of the accounts paying at the start of a period: the share lost (logo churn), the MRR lost (revenue churn), and the MRR they bring at the end (NRR).

Of the customers paying on 1 January, how many are gone a year later, and how much of their revenue is left? Take the accounts paying at the start: logo churn = the lost ones / all of them; revenue churn weighs them by their MRR; net revenue retention (NRR) = their MRR at the end / their MRR at the start, expansion and contraction included, new accounts never.

WITH start AS (
  SELECT account_id, mrr
  FROM account_mrr
  WHERE month = DATE '2025-01-01' AND mrr > 0
)
SELECT 100.0 * COUNT(CASE WHEN COALESCE(e.mrr, 0) = 0 THEN 1 END) / COUNT(*) AS logo_churn_pct,
       100.0 * SUM(CASE WHEN COALESCE(e.mrr, 0) = 0 THEN s.mrr END) / SUM(s.mrr) AS revenue_churn_pct,
       100.0 * SUM(COALESCE(e.mrr, 0)) / SUM(s.mrr) AS nrr_pct
FROM start s
LEFT JOIN account_mrr e
  ON e.account_id = s.account_id AND e.month = DATE '2026-01-01';

Gross revenue retention (GRR) caps each account at its starting MRR, LEAST(COALESCE(e.mrr, 0), s.mrr): it never exceeds 100 %.

The trap. The base is the accounts paying at the start, for the numerator and the denominator alike. Divide by every account (Free ones included) or by those at the end, and churn comes out too low. An inner join to the end month drops the accounts that left, and NRR jumps above 100 %.

-- Account 3 has no row in 2026 (gone), 6 was on Free at the start, 7 is new: neither is in the base.
WITH account_mrr(account_id, month, mrr) AS (VALUES
  (1, DATE '2025-01-01', 100), (1, DATE '2026-01-01', 160),
  (2, DATE '2025-01-01', 40),  (2, DATE '2026-01-01', 0),
  (3, DATE '2025-01-01', 50),
  (4, DATE '2025-01-01', 80),  (4, DATE '2026-01-01', 60),
  (5, DATE '2025-01-01', 300), (5, DATE '2026-01-01', 330),
  (6, DATE '2025-01-01', 0),   (6, DATE '2026-01-01', 120),
  (7, DATE '2026-01-01', 200)
),
start AS (
  SELECT account_id, mrr
  FROM account_mrr
  WHERE month = DATE '2025-01-01' AND mrr > 0
)
SELECT COUNT(*) AS start_accounts,
       ROUND(100.0 * COUNT(CASE WHEN COALESCE(e.mrr, 0) = 0 THEN 1 END) / COUNT(*), 1) AS logo_churn_pct,
       ROUND(100.0 * SUM(CASE WHEN COALESCE(e.mrr, 0) = 0 THEN s.mrr END) / SUM(s.mrr), 1) AS revenue_churn_pct,
       ROUND(100.0 * SUM(LEAST(COALESCE(e.mrr, 0), s.mrr)) / SUM(s.mrr), 1) AS grr_pct,
       ROUND(100.0 * SUM(COALESCE(e.mrr, 0)) / SUM(s.mrr), 1) AS nrr_pct
FROM start s
LEFT JOIN account_mrr e ON e.account_id = s.account_id AND e.month = DATE '2026-01-01';
start_accountslogo_churn_pctrevenue_churn_pctgrr_pctnrr_pct
540.015.880.796.5
Try it in Randori