Dataford
Interview Guides
Upgrade
All questions/SQL & Data Manipulation/Compare Asana Retention Cohorts by Channel

Compare Asana Retention Cohorts by Channel

Hard
SQL & Data Manipulation
Asked at 1 company1JoinsAggregationsWindow Functions
Also asked at
Asana

Problem

Task

Asana’s growth team wants to compare early retention for users acquired through ChatGPT versus all other acquisition channels. Write a PostgreSQL query that builds weekly signup cohorts and reports week 0 through week 4 retention for each cohort and acquisition segment.

Requirements

  1. Define each user’s cohort by the week of signup from users.signup_date.
  2. Split users into two acquisition segments:
    • ChatGPT when acquisition_channel = 'ChatGPT'
    • Other for every other non-null channel Exclude users with a null acquisition channel.
  3. Count a user as retained in week n if they had at least one activity in Asana during the nth week after signup, using activity_date from user_activity.
  4. Return one row per cohort_week, acquisition_segment, and week_number for weeks 0-4.
  5. Include cohort_size, retained_users, and retention_rate rounded to 4 decimal places.
  6. Order the final output by cohort_week, acquisition_segment, and week_number.

Table Definitions

users

columntypedescription
user_idINTUnique user id
signup_dateDATEDate the user signed up for Asana
acquisition_channelVARCHAR(50)Signup acquisition source
workspace_idINTFirst workspace joined

user_activity

columntypedescription
activity_idINTUnique activity event id
user_idINTUser who performed the activity
activity_dateDATEDate of the activity
activity_typeVARCHAR(50)Activity performed in Asana

Sample Data

users

user_idsignup_dateacquisition_channelworkspace_id
32024-01-10Paid Search101
12024-01-02ChatGPT101
82024-01-17Referral105
52024-01-09ChatGPT103

user_activity

activity_iduser_idactivity_dateactivity_type
10412024-01-15task_completed
10112024-01-03task_created
11252024-01-23comment_added
11882024-02-15task_created

Expected Output

cohort_weekacquisition_segmentweek_numbercohort_sizeretained_usersretention_rate
2024-01-01ChatGPT0221.0000
2024-01-01ChatGPT1210.5000
2024-01-01Other0210.5000
2024-01-15Other4111.0000

Schema

users
ColumnTypeDescription
user_idPKINTUnique Asana user identifier
signup_dateDATEDate the user signed up
acquisition_channelVARCHAR(50)Marketing or referral source that acquired the user
workspace_idINTFirst Asana workspace the user joined
user_activity
ColumnTypeDescription
activity_idPKINTUnique activity event identifier
user_idINTUser who performed the activity
activity_dateDATEDate of the Asana activity
activity_typeVARCHAR(50)Type of activity performed

Sample Data

Example 1
Input{"users":[["3","2024-01-10","Paid Search","101"],["1","2024-01-02","ChatGPT","101"],["8","2024-01-17","Referral","105"],["5","2024-01-09","ChatGPT","103"],["2","2024-01-04","Organic Search","102"],["10","2024-01-18","Paid Social","106"],["4","2024-01-11",null,"102"],["6","2024-01-15","ChatGPT","104"],["7","2024-01-16","ChatGPT","104"],["9","2024-01-22","ChatGPT",null],["11","2024-01-17","Instagram","105"],["12","2024-01-21","Newsletter","105"],["13","2024-01-02","null","107"],["14","2024-01-18",Output[["2023-12-25","Other","0","3","0","0.0000"],["2023-12-25","Other","1","3","0","0.0000"],["2023-12-25","Other","2","3","0","0.0000"],["2023-12-25","Other","3","3","0","0.0000"],["2023-12-25","Other","4","3","0","0.0000"],["2024-01-01","ChatGPT","0","1","1","1.0000"],["2024-01-01","ChatGPT","1","1","1","1.0000"],["2024-01-01","ChatGPT","2","1","0","0.0000"],["2024-01-01","ChatGPT","3","1","0","0.0000"],["2024-01-01","ChatGPT","4","1","0","0.0000"],["2024-01-01","Other","0","3","0","0.0000"],["202

Problem

Task

Asana’s growth team wants to compare early retention for users acquired through ChatGPT versus all other acquisition channels. Write a PostgreSQL query that builds weekly signup cohorts and reports week 0 through week 4 retention for each cohort and acquisition segment.

Requirements

  1. Define each user’s cohort by the week of signup from users.signup_date.
  2. Split users into two acquisition segments:
    • ChatGPT when acquisition_channel = 'ChatGPT'
    • Other for every other non-null channel Exclude users with a null acquisition channel.
  3. Count a user as retained in week n if they had at least one activity in Asana during the nth week after signup, using activity_date from user_activity.
  4. Return one row per cohort_week, acquisition_segment, and week_number for weeks 0-4.
  5. Include cohort_size, retained_users, and retention_rate rounded to 4 decimal places.
  6. Order the final output by cohort_week, acquisition_segment, and week_number.

Table Definitions

users

columntypedescription
user_idINTUnique user id
signup_dateDATEDate the user signed up for Asana
acquisition_channelVARCHAR(50)Signup acquisition source
workspace_idINTFirst workspace joined

user_activity

columntypedescription
activity_idINTUnique activity event id
user_idINTUser who performed the activity
activity_dateDATEDate of the activity
activity_typeVARCHAR(50)Activity performed in Asana

Sample Data

users

user_idsignup_dateacquisition_channelworkspace_id
32024-01-10Paid Search101
12024-01-02ChatGPT101
82024-01-17Referral105
52024-01-09ChatGPT103

user_activity

activity_iduser_idactivity_dateactivity_type
10412024-01-15task_completed
10112024-01-03task_created
11252024-01-23comment_added
11882024-02-15task_created

Expected Output

cohort_weekacquisition_segmentweek_numbercohort_sizeretained_usersretention_rate
2024-01-01ChatGPT0221.0000
2024-01-01ChatGPT1210.5000
2024-01-01Other0210.5000
2024-01-15Other4111.0000

Schema

users
ColumnTypeDescription
user_idPKINTUnique Asana user identifier
signup_dateDATEDate the user signed up
acquisition_channelVARCHAR(50)Marketing or referral source that acquired the user
workspace_idINTFirst Asana workspace the user joined
user_activity
ColumnTypeDescription
activity_idPKINTUnique activity event identifier
user_idINTUser who performed the activity
activity_dateDATEDate of the Asana activity
activity_typeVARCHAR(50)Type of activity performed

Sample Data

Example 1
Input{"users":[["3","2024-01-10","Paid Search","101"],["1","2024-01-02","ChatGPT","101"],["8","2024-01-17","Referral","105"],["5","2024-01-09","ChatGPT","103"],["2","2024-01-04","Organic Search","102"],["10","2024-01-18","Paid Social","106"],["4","2024-01-11",null,"102"],["6","2024-01-15","ChatGPT","104"],["7","2024-01-16","ChatGPT","104"],["9","2024-01-22","ChatGPT",null],["11","2024-01-17","Instagram","105"],["12","2024-01-21","Newsletter","105"],["13","2024-01-02","null","107"],["14","2024-01-18",Output[["2023-12-25","Other","0","3","0","0.0000"],["2023-12-25","Other","1","3","0","0.0000"],["2023-12-25","Other","2","3","0","0.0000"],["2023-12-25","Other","3","3","0","0.0000"],["2023-12-25","Other","4","3","0","0.0000"],["2024-01-01","ChatGPT","0","1","1","1.0000"],["2024-01-01","ChatGPT","1","1","1","1.0000"],["2024-01-01","ChatGPT","2","1","0","0.0000"],["2024-01-01","ChatGPT","3","1","0","0.0000"],["2024-01-01","ChatGPT","4","1","0","0.0000"],["2024-01-01","Other","0","3","0","0.0000"],["202
Practice SQL
PostgreSQL
Open on desktop for the full SQL editor with syntax highlighting and autocomplete.
Up next
AsanaCompare ChatGPT Acquisition PerformanceMediumIntuitCompare User Retention by CohortMediumRipplingCompare Channel Retention by CohortMedium
Next question