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.
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.
The question
The SQL Taptic generates
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
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.
How this query works
What it returns
Revenue cohort matrix showing monthly and cumulative revenue per cohort across months 0 through 5.
Why it matters
FAQ
Generate this automatically
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/moNo credit card required. Connect your data source in under 5 minutes.
Compare tools