Skip to content

Weekly sign-up cohorts and next-week buyers

MediumFull bankCohorts and retentionDates and timeRatios and percentages18 min3 hidden datasets

The task

The marketing team tracks whether new sign-ups come back to buy. Group users into weekly cohorts and measure repeat buying in the following week.

Rules:

  • A user's cohort is the calendar week of signups.signed_up_at. Weeks run Monday to Sunday, and cohort_week is the Monday.
  • A user is retained if they made at least one purchase (purchases.purchased_at) in the next calendar week, Monday to Sunday. Purchases in the cohort's own week do not count.
  • Count users, not purchases.
  • Only include a cohort when its next week is complete in the data: the Sunday that ends the next week must be on or before the date of the latest purchased_at in purchases.
  • A cohort with no retained users still appears, with 0.

Return cohort_week, cohort_size, retained_users and retention_pct (retained users as a percentage of the cohort, rounded to 1 decimal place). Sort by cohort_week.

Expected output

cohort_weekcohort_sizeretained_usersretention_pct
  • Sorted by cohort_week ascending.
  • Numbers rounded to 1 decimal place.
  • Checked on the sample and on 3 hidden datasets. How grading works

Tables Marketing team · click a name to insert it

campaigns10 rows in the sample

One row per campaign. Key: campaign_id.

intUnique id.
textName.
textsearch, social, video, email or affiliate.
dateFirst day live.
dateLast day live. NULL if still running.
numeric(10,2)Budget per day, USD.
ad_daily969 rows in the sample

One row per campaign per day it served ads. Days with no delivery have no row. Key: campaign_id, day.

intThe campaign.
dateThe day.
intTimes an ad was shown.
intClicks.
numeric(10,2)Money spent, USD.
signups2,108 rows in the sample

One row per new user. campaign_id is the campaign credited with the sign-up. Key: user_id.

intUnique id.
timestampWhen they signed up (UTC).
intCredited campaign. NULL for organic sign-ups.
textTwo-letter country code.
purchases2,294 rows in the sample

One row per paid order by a user. Key: purchase_id.

intUnique id.
intBuyer.
timestampWhen (UTC).
numeric(10,2)Order value, USD.

Related questions

Loading the editor and PostgreSQL