Build a Monthly Spend Retention Matrix by Card Acquisition Cohort

Last updated: November 29, 2026

Quick Overview

Produce a cohort table where each row is the month a card account was opened, each column is months since opening (0 to 12), and each cell is the share of that cohort with at least one purchase in that month.

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

0

0

0 solved


Produce a cohort table where each row is the month a card account was opened, each column is months since opening (0 to 12), and each cell is the share of that cohort with at least one purchase in that month.

Capital One card product teams compare cohorts to see whether a new offer, like a bigger welcome bonus, brings in customers who keep spending after the bonus is earned. The interviewer is checking month-offset arithmetic, correct denominators, and how you handle cells that should read zero or are not yet observable.

What the Interviewer Expects
  • Computes month offset as a whole-month difference, not days divided by 30
  • Uses cohort size as the denominator, including never-active accounts
  • Counts distinct accounts per cell rather than transactions
  • Distinguishes a true zero from a cell that is not yet observable
  • Pivots the long result into a matrix in SQL or pandas
Key Topics to Cover
retention
cohort matrix
month offset
denominators
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
  • How would you read a cohort that drops sharply at month 4?
  • How would you change this to dollar retention instead of active retention?
  • How do you compare cohorts that have different acquisition channel mixes?
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
  • accounts(account_id, open_date) and transactions(account_id, txn_date, amount, txn_type).
  • Active in a month means at least one purchase with amount > 0 in that calendar month.
  • Month offset 0...
Approach
  1. Cohort per account: DATE_TRUNC('month', open_date).
  2. Distinct active months per account.
  3. Offset = (year diff) * 12 + (month diff).
  4. Count distinct active accounts per (cohort, offset) an...

Submit Your Answer
Markdown supported