Event contract
Fields the query expects
| Field | Type | Why it exists |
|---|---|---|
| timestamp_utc | Timestamp | Meaningful activity time. |
| team_id | Utf8 | Account identifier. |
| event_name | Utf8 | Qualifying product activity. |
Copy the query
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_month | retained_teams | reactivated_teams |
|---|---|---|
| 2026-05 | 442 | 38 |
| 2026-06 | 468 | 51 |
| 2026-07 | 492 | 64 |
Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.
How the SQL works
- 1The monthly CTE deduplicates multiple qualifying actions by account and month.
- 2LAG finds the account’s previous active month.
- 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
Put the recipe to work
Related instrumentation and guides
Continue the analysis
Build a Signup-to-Activation Funnel in SQL
Calculate unique-user conversion through signup, onboarding, integration, and first-value milestones.
Open recipeCalculate Weekly Cohort Retention
Group users by first activity week and measure the percentage returning in later weeks.
Open recipeFind Features Used Before Upgrade
Join feature events to upgrade events and rank behaviors that occur before paid conversion.
Open recipeRun 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.