ARR/NRR Analytics Pack
This analytics pack provides a complete set of SQL models and queries to track Annual Recurring Revenue (ARR), Net Revenue Retention (NRR), cohorts, expansions, contractions, and churn for a SaaS business. It's designed to be modular (e.g., for dbt, Looker, or any SQL-based BI tool) and focuses on monthly granularity.
Key Metrics Covered
- ARR: MRR × 12 (current and historical).
- NRR:
(Ending MRR from cohort + Expansions - Contractions - Churn) / Starting MRR from cohort × 100%.
- Cohorts: Customer cohorts by first MRR > $0 month; tracks retention % and NRR over time.
- Expansions: MRR increases month-over-month (upsells/cross-sells).
- Contractions: MRR decreases month-over-month (downgrades).
- Churn:
- Customer Churn: % of customers lost.
- Revenue Churn: MRR lost from cancellations.
Data Model Assumptions
Assumes a standard Stripe/Stripe-like schema:
-
subscriptions table:
| Column | Type | Description |
|---|
id | UUID | Subscription ID |
customer_id | UUID | FK to customers |
starts_at | DATE | Subscription start |
ends_at | DATE | Subscription end (NULL if active) |
mrr | DECIMAL | Monthly recurring revenue (USD) |
status | STRING | 'active', 'canceled', 'trialed' |
-
customers table:
| Column | Type | Description |
|---|
id | UUID | Customer ID |
created_at | TIMESTAMP | Signup date |
-
Date spine (month_spine): A table/view with month (DATE, first of month) from your earliest data to current.
-
SQL Dialect: Postgres/Snowflake compatible (uses generate_series).
-
Granularity: Monthly (YYYY-MM-01).
-
Currency: USD; assumes no multi-currency.
If your schema differs (e.g., uses invoices or charges), adapt the base MRR query.
SQL Models
Run these in sequence (e.g., as dbt models). All use CTEs for reusability.
1. Base Model: customer_monthly_mrr.sql
Snapshots MRR per customer per month (active subs on the 1st of the month).
{{ config(materialized='table') }}
WITH active_months AS (
SELECT
s.customer_id,
s.mrr,
gs.month
FROM {{ ref('subscriptions') }} s
CROSS JOIN UNNEST(
GENERATE_SERIES(
DATE_TRUNC('month', s.starts_at),
COALESCE(DATE_TRUNC('month', s.ends_at), CURRENT_DATE),
INTERVAL '1 MONTH'
)
) AS gs(month)
WHERE s.status IN ('active', 'trialing') -- Exclude canceled pre-snapshot
AND gs.month <= CURRENT_DATE
),
customer_monthly_mrr AS (
SELECT
customer_id,
month,
COALESCE(SUM(mrr), 0) AS mrr
FROM active_months
GROUP BY 1, 2
)
SELECT * FROM customer_monthly_mrr
2. Customer Cohorts: customer_cohorts.sql
First month with MRR > $0.
{{ config(materialized='table') }}
SELECT
cm.customer_id,
MIN(cm.month) AS cohort_month
FROM {{ ref('customer_monthly_mrr') }} cm
WHERE cm.mrr > 0
GROUP BY 1
3. Cohort Analysis: cohort_retention_nrr.sql
Retention % and NRR by cohort and age (months since cohort).
{{ config(materialized='table') }}
WITH cohort_grid AS (
SELECT
cc.cohort_month,
cm.month AS snapshot_month,
DATEDIFF('month', cc.cohort_month, cm.month) AS cohort_age_months,
COUNT(DISTINCT cm.customer_id) AS customers_retained,
SUM(cm.mrr) AS snapshot_mrr
FROM {{ ref('customer_cohorts') }} cc
LEFT JOIN {{ ref('customer_monthly_mrr') }} cm
ON cm.customer_id = cc.customer_id
AND cm.month >= cc.cohort_month
GROUP BY 1, 2, 3
),
cohort_sizes AS (
SELECT
cohort_month,
MAX(CASE WHEN cohort_age_months = 0 THEN customers_retained END) AS cohort_customers,
MAX(CASE WHEN cohort_age_months = 0 THEN snapshot_mrr END) AS cohort_mrr
FROM cohort_grid
GROUP BY 1
)
SELECT
cg.*,
cs.cohort_customers,
cs.cohort_mrr,
cg.customers_retained / NULLIF(cs.cohort_customers, 0) AS retention_pct,
cg.snapshot_mrr / NULLIF(cs.cohort_mrr, 0) AS nrr_pct,
(cg.snapshot_mrr - cs.cohort_mrr) / cs.cohort_mrr AS nrr_change_pct
FROM cohort_grid cg
JOIN cohort_sizes cs ON cs.cohort_month = cg.cohort_month
ORDER BY 1, 3
4. Monthly Changes: monthly_expansions_contractions_churn.sql
Month-over-month breakdowns for expansions, contractions, churn.
{{ config(materialized='table') }}
WITH prev_mrr AS (
SELECT
*,
LAG(mrr) OVER (PARTITION BY customer_id ORDER BY month) AS prev_mrr
FROM {{ ref('customer_monthly_mrr') }}
),
changes AS (
SELECT
month,
customer_id,
mrr AS curr_mrr,
prev_mrr,
CASE
WHEN prev_mrr = 0 AND curr_mrr > 0 THEN 'new'
WHEN prev_mrr > 0 AND curr_mrr = 0 THEN 'churn'
WHEN prev_mrr > 0 AND curr_mrr > 0 AND curr_mrr > prev_mrr THEN 'expansion'
WHEN prev_mrr > 0 AND curr_mrr > 0 AND curr_mrr < prev_mrr THEN 'contraction'
WHEN prev_mrr > 0 AND curr_mrr > 0 AND curr_mrr = prev_mrr THEN 'flat'
ELSE 'other'
END AS change_type,
curr_mrr - prev_mrr AS mrr_delta
FROM prev_mrr
WHERE month > (SELECT MIN(month) FROM {{ ref('customer_monthly_mrr') }})
)
SELECT
month,
COUNT(CASE WHEN change_type = 'churn' THEN 1 END) AS churned_customers,
SUM(CASE WHEN change_type = 'churn' THEN prev_mrr END) AS churned_mrr,
COUNT(CASE WHEN change_type = 'expansion' THEN 1 END) AS expansion_customers,
SUM(CASE WHEN change_type = 'expansion' THEN mrr_delta END) AS expansion_mrr,
COUNT(CASE WHEN change_type = 'contraction' THEN 1 END) AS contraction_customers,
SUM(CASE WHEN change_type = 'contraction' THEN ABS(mrr_delta) END) AS contraction_mrr,
COUNT(DISTINCT CASE WHEN prev_mrr > 0 THEN customer_id END) AS prior_customers,
SUM(CASE WHEN prev_mrr > 0 THEN prev_mrr END) AS prior_mrr,
(SUM(curr_mrr) / NULLIF(SUM(prev_mrr), 0)) AS nrr_pct -- Overall monthly NRR
FROM changes
GROUP BY 1
ORDER BY 1 DESC
5. ARR Summary: arr_summary.sql
Current and historical ARR.
{{ config(materialized='view') }}
SELECT
month,
SUM(mrr) AS mrr,
SUM(mrr) * 12 AS arr,
AVG(mrr) AS avg_mrr_per_customer
FROM {{ ref('customer_monthly_mrr') }}
GROUP BY 1
ORDER BY 1 DESC
Dashboard Visualizations (e.g., for Looker, Tableau, Metabase)
-
Cohort Heatmap (cohort_retention_nrr):
- Rows: Cohort month (last 24).
- Columns: Cohort age (0-12 months).
- Color: Retention % or NRR % (darker = better).
- Add line chart: Median NRR over time.
-
NRR Waterfall (monthly_expansions_contractions_churn):
- Stacked bar: Starting MRR → +Expansions → -Contractions → -Churn → Ending MRR.
- KPI cards: NRR %, Churn %, Expansion %, Contraction %.
-
Churn Breakdown:
- Pie/Donut: Churned MRR by segment (e.g., join with customer attributes).
- Trend line: Monthly churn rate (churned_mrr / prior_mrr).
-
ARR Trend (arr_summary + changes):
- Line chart: ARR over time, with annotations for expansions/churn.
-
Customer-Level Drill:
- Table: Top expanders/contractors (filter
changes where |mrr_delta| > threshold).
Usage Notes
- Materialize: Use incremental models for scale (e.g., dbt incrementals on
month).
- Filters: Add
WHERE month >= '2023-01-01' for recency.
- Customization:
- Multi-sub customers: Handled via SUM(mrr).
- Proration/credits: Adjust
mrr in source table.
- Segments: JOIN
customers for cohort_month filters (e.g., by segment).
- Example NRR Calc: For Jan cohort, Month 3 NRR = snapshot_mrr_month3 / cohort_mrr.
- Testing: Seed sample data and verify: NRR > 100% if expansions > churn+contractions.
Deploy this pack and iterate! If you provide your schema or tool (e.g., dbt project), I can refine. 🕵️♂️