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 . SQL compatibility, event contract, synthetic output, and operational caveats. Review standards and ownership

Question answered

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

A user can disappear and later return. Separating reactivation from uninterrupted retention keeps lifecycle reporting honest.

Event contract

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. The deterministic sample output is synthetic and reviewed separately; validate field types, thresholds, and business definitions 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
Indexable SVG of the deterministic example output. Download it for an article, runbook, or design review with attribution.

Reproduce the example

Download the public fixture

The JSON bundle includes the typed event contract, 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 decide

  • 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

Put the recipe to work

Related instrumentation and guides

Continue the analysis

Run it on real 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