KatInterview

Monthly Channel Cohorts: Measuring First-Month Account Usage

SQL & DataModel answer
MediumModel answerSQL & Datasqlcohort-analysisleft-join

Last updated

Write a SQL report of how many new banking users make three or more completed debits totaling at least $50 in their first 30 days, grouped by signup month and channel, excluding immature cohorts.

Context

A digital bank wants to know how well each marketing channel brings in users who actually use their accounts. A user who opens an account but never spends contributes little value, so the team tracks a short-term "first-month usage" measure.

A user counts as activated if, within the first 30 days after signup (day 0 through day 30, both inclusive), they have:

  • at least 3 qualifying transactions, and
  • those transactions sum to at least $50.00.

A qualifying transaction has transaction_type = 'debit' and status = 'completed'.

Schema

users

ColumnTypeDescription
user_idINTPrimary key
signup_dateDATEDay the account was opened
acquisition_channelVARCHARMarketing channel, e.g. 'organic', 'paid_search', 'referral'

transactions

ColumnTypeDescription
transaction_idINTPrimary key
user_idINTReferences users.user_id
transaction_dateDATEDay of the transaction
transaction_typeVARCHAR'debit', 'deposit' or 'transfer'
statusVARCHAR'completed', 'pending', 'declined' or 'reversed'
amountDECIMAL(10, 2)Positive USD amount

Task

Write a SQL query (PostgreSQL syntax is fine) that returns one row per signup month and acquisition channel with these columns:

  1. cohort_month: first day of the signup month as text 'YYYY-MM-01'.
  2. acquisition_channel
  3. total_users: users in that month and channel.
  4. activated_users: users from that group who meet the activation rule.
  5. activation_rate_pct: activated_users * 100.0 / total_users, rounded to 2 decimals.

Rules

  • Count only transactions with status = 'completed' and transaction_type = 'debit'.
  • A transaction counts only if its date falls between signup_date and signup_date + 30 days, inclusive.
  • Leave out users who signed up within the last 30 days relative to CURRENT_DATE, since their 30-day window is not yet fully observed.
  • Sort by cohort_month ascending, then acquisition_channel ascending.

Sample output

cohort_month | acquisition_channel | total_users | activated_users | activation_rate_pct
-------------+---------------------+-------------+-----------------+--------------------
2023-01-01   | organic             |        1200 |             480 |               40.00
2023-01-01   | paid_search         |        2500 |             750 |               30.00
2023-01-01   | referral            |         800 |             440 |               55.00
2023-02-01   | organic             |        1350 |             567 |               42.00

What to cover

Give the query, explain why it is correct, discuss edge cases, and state any assumptions (for example, how you interpret the maturity cutoff).

Hints

Hint 1

Split the work into stages: first pick the eligible users, then compute per-user transaction counts and totals inside the window, then aggregate by month and channel.

Hint 2

Users with no qualifying transactions must still appear in `total_users`. Think about which table should drive the join and which join type keeps them.

Hint 3

Aggregate transactions to one row per user before joining back, so the final `COUNT(*)` counts users and not transactions. Use conditional aggregation (`FILTER` or `CASE`) for the numerator.

Hint 4

Decide whether the maturity cutoff should be strict (`<`) or not, and justify it: a user whose day 30 is today has an unfinished window.