Compute Net Revenue Retention by Merchant Activation Cohort

Last updated: November 29, 2026

Quick Overview

Using merchant activation dates and succeeded charges with Stripe fee revenue, write SQL that produces, for each monthly activation cohort and each month since activation, the logo retention and net revenue retention relative to the cohort's first month.

Stripe
Data Manipulation (SQL/Python)
Data Scientist
Stripe
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Using merchant activation dates and succeeded charges with Stripe fee revenue, write SQL that produces, for each monthly activation cohort and each month since activation, the logo retention and net revenue retention relative to the cohort's first month.

Stripe's revenue grows when existing merchants grow, so net revenue retention by cohort is a standard lens for finance and growth teams, and SQL rounds use it to test cohort construction. The interviewer looks for correct cohort assignment, month indexing, a stable month 0 baseline, and awareness that NRR can exceed 100% while logo retention falls.

What the Interviewer Expects
  • Assigns each merchant to a cohort by activation month, not first charge month, unless justified
  • Aggregates revenue to merchant-month before joining to avoid fan-out
  • Computes month_index as a calendar month difference
  • Uses month 0 revenue as the baseline via a window, guarding against divide by zero
  • Reports logo retention and revenue retention side by side
  • Calls out partial months and missing-month gaps
Key Topics to Cover
cohort analysis
net revenue retention
window functions
date arithmetic
aggregation grain
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • Why can NRR exceed 100% while logo retention is under 60%?
  • How would you exclude refunds and disputes from fee revenue?
  • A cohort's month 0 is tiny because merchants activated on the 30th. How would you fix the baseline?
  • How would you produce this as a triangle with months as columns?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

merchants(merchant_id, activated_at) and charges(merchant_id, created_at, status, fee_revenue). Cohort = month of activation. Revenue = sum of Stripe fee revenue on succeeded charges. NRR at month...

Approach
  1. cohorts: merchant to activation month.
  2. monthly: aggregate charges to one row per merchant-month first, so the join cannot fan out.
  3. Join and compute month_index as the year*12+month diff...

Submit Your Answer
Markdown supported