Skip to content
Telemetry
Product analytics SQL recipe

Measure churn and reactivation by cohort

Classify accounts as retained, churned, or reactivated from recurring meaningful product activity.

Advancedproduct_eventsReviewed 2026-07-27Tested with Apache DataFusion 45.2.0

Reviewed by the Telemetry product team on . We checked the SQL syntax, required event fields, sample results, and limits on using the query. Who reviews this page

Question answered

How many accounts churned, stayed active, or returned this month?

A user can stop using the product and return later. Count that return as reactivation so it does not inflate uninterrupted retention.

Event schema

Fields the query expects

FieldTypeWhy it exists
timestamp_utcTimestampMeaningful activity time.
team_idUtf8Account identifier.
event_nameUtf8Qualifying product activity.
DataFusion SQL

Copy the query

sql
WITH monthly AS (
  SELECT DISTINCT
    team_id,
    date_trunc('month', timestamp_utc) AS activity_month
  FROM product_events
  WHERE timestamp_utc >= now() - INTERVAL '180 days'
    AND event_name IN ('feature_used', 'query_run', 'dashboard_viewed')
),
transitions AS (
  SELECT
    activity_month,
    team_id,
    LAG(activity_month) OVER (
      PARTITION BY team_id ORDER BY activity_month
    ) AS previous_active_month
  FROM monthly
)
SELECT
  activity_month,
  SUM(CASE
    WHEN previous_active_month = activity_month - INTERVAL '1 month' THEN 1 ELSE 0
  END) AS retained_teams,
  SUM(CASE
    WHEN previous_active_month < activity_month - INTERVAL '1 month' THEN 1 ELSE 0
  END) AS reactivated_teams
FROM transitions
GROUP BY activity_month
ORDER BY activity_month;

This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. We review the synthetic sample output separately. Check field types, thresholds, and counting rules against your own data. Read the testing methodology.

Query result

Retained and reactivated teams

Reactivated accounts increased across the three monthly cohorts.

activity_monthretained_teamsreactivated_teams
2026-0544238
2026-0646851
2026-0749264

Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.

Retained and reactivated teams: static chart of synthetic retained_teams values from the Measure churn and reactivation by cohort example result
Download this SVG chart of the sample results for an article, runbook, or design review. Please credit Telemetry.

Reproduce the example

Download the sample data

The JSON bundle includes the event schema with field types, illustrative input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.

How the SQL works

  1. 1The monthly CTE deduplicates multiple qualifying actions by account and month.
  2. 2LAG finds the account's previous active month.
  3. 3A one-month gap means uninterrupted retention; a larger gap means reactivation.

Edge cases to check

  • This query does not count churned accounts that never returned; compute them from the previous cohort with a left join.
  • Use account activity for collaborative products where one user does not represent customer health.
  • Exclude internal and test teams consistently.

Recommended dashboard

  • Stacked bars: retained and reactivated teams
  • Stat: gross logo retention
  • Table: reactivated accounts and first returning action

Alert guidance

Use lifecycle shifts for scheduled review rather than paging.

Read alert setup

Set up the events this query needs

Related instrumentation and guides

Continue the analysis

Run it on your events

Create a table, adapt the fields, and save the result

Start free, send structured events, and use the query result as a chart, shared dashboard widget, or alert input.

Get an API key