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-27

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 recipe is read-only and reviewed against Telemetry's DataFusion query patterns. Sample output is deterministic and synthetic; validate field types, thresholds, and business definitions against your own data.

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.

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