HomeQuery LibraryDatabase

How much revenue does each customer cohort generate over time?

Revenue cohort analysis shows whether newer cohorts are more or less valuable than older ones. This query tracks cumulative revenue by signup month cohort across subsequent months.

📊 Any SQL database👥 Finance and growth teams🔤 Plain-English → SQL

This is part of the Taptic Data Database query library. Explore related queries: SQL query for monthly revenue trend, SQL query for top customers by revenue, SQL query for revenue by region, and more.

Show me cumulative revenue by customer signup cohort over their first 6 months
Revenue Cohort Analysis Query — generated by Taptic Data AI
WITH customer_cohorts AS (
  SELECT
    customer_id,
    DATE_TRUNC('month', signup_date)::date AS cohort_month
  FROM customers
),
cohort_revenue AS (
  SELECT
    cc.cohort_month,
    EXTRACT(YEAR FROM AGE(DATE_TRUNC('month', o.order_date), cc.cohort_month)) * 12
      + EXTRACT(MONTH FROM AGE(DATE_TRUNC('month', o.order_date), cc.cohort_month))
                                      AS month_number,
    SUM(o.total_amount)              AS revenue
  FROM orders o
  JOIN customer_cohorts cc USING (customer_id)
  WHERE o.status NOT IN ('cancelled', 'refunded')
  GROUP BY cc.cohort_month, month_number
)
SELECT
  TO_CHAR(cohort_month, 'YYYY-MM')   AS cohort,
  month_number,
  ROUND(revenue::numeric, 2)        AS monthly_revenue,
  ROUND(SUM(revenue) OVER (
    PARTITION BY cohort_month
    ORDER BY month_number
  )::numeric, 2)                     AS cumulative_revenue
FROM cohort_revenue
WHERE month_number BETWEEN 0 AND 5
  AND cohort_month >= NOW() - INTERVAL '12 months'
ORDER BY cohort_month, month_number
Schema-aware SQL generated from plain English30 lines

This query was generated by Taptic Data from plain English against a real Any SQL database schema. In Taptic, you type the question — the AI writes the SQL, runs it, and returns the result. You can edit the SQL, ask for explanations, and save it as a refreshable report.

Breaking it down line by line

  1. CTE "customer_cohorts" assigns each customer to their first month
  2. CTE "cohort_revenue" calculates revenue by cohort by months-since-signup
  3. Window function SUM OVER (PARTITION BY cohort ORDER BY month) creates the cumulative total
  4. Limited to months 0-5 (first 6 months) and the last 12 cohorts to keep the output manageable
  5. Each row shows both the monthly and cumulative revenue for that cohort at that month number

Result description

Revenue cohort matrix showing monthly and cumulative revenue per cohort across months 0 through 5.

The business impact

Revenue cohort analysis reveals whether your LTV is improving cohort over cohort. If your March cohort generates $50K in their first 3 months but your June cohort only generates $30K, your product or acquisition quality is declining — and headline revenue growth is masking it.

Common questions

How do I generate a "Revenue Cohort Analysis Query" query automatically?
In Taptic Data, type "Show me cumulative revenue by customer signup cohort over their first 6 months" and the AI generates schema-aware SQL against your real Any SQL database data — no manual writing required.
What database does this query work with?
This query is designed for Any SQL database. Taptic reads your live schema so the generated SQL always matches your actual table and column names.
Can I edit the generated SQL?
Yes. Taptic shows you the exact SQL it generated. You can edit it directly, ask the AI to explain any line, or request a revision in plain English.
Can I save this as a scheduled report?
Yes. Once you run this query in Taptic, you can save it as a report, add charts and KPIs, and schedule it to email your team on any cadence — daily, weekly, or monthly.

Skip the SQL. Ask the question.

In Taptic Data, you type "Show me cumulative revenue by customer signup cohort over th..." and this SQL runs automatically against your real Any SQL database data.

Try Taptic Free — $29.99/mo

No credit card required. Connect your data source in under 5 minutes.