Skip to content

Instantly share code, notes, and snippets.

@PedroMartinSteenstrup
Last active February 23, 2021 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PedroMartinSteenstrup/0bd88137ee1fc647c9888b1344207101 to your computer and use it in GitHub Desktop.
Save PedroMartinSteenstrup/0bd88137ee1fc647c9888b1344207101 to your computer and use it in GitHub Desktop.
updated version of virality as a factor of NPS score
WITH viralit AS (
Select host_id,
count(distinct IFF(DATE_SIGNED_UP is not null, GUEST_ID, NULL)) count_signups,
count(distinct IFF(DATE_TRANSFERRED is not null, GUEST_ID, NULL)) count_mnus
from virality.referral
GROUP BY 1),
nps AS (SELECT bnps.user_id,
bnps.nps_score AS nps_score,
bnps.respond_date,
rank() over (partition by bnps.USER_ID order by bnps.RESPOND_DATE desc) rank
FROM REPORTS.REPORT_NPS bnps
WHERE 1 = 1
AND bnps.NPS_SCORE is not null
GROUP BY 1, 2, 3)
SELECT nps.nps_score AS nps,
count(distinct nps.user_id) AS nps_respondents,
count(distinct viralit.host_id) AS people_who_invited,
count(distinct IFF(viralit.count_mnus > 0, viralit.host_id, NULL)) AS count_host_mnus,
round(sum(viralit.count_mnus) / count(distinct host_id), 2) AS mnus_per_host,
round(sum(viralit.count_signups) / count(distinct host_id), 2) AS signups_per_host
FROM nps
LEFT JOIN viralit ON nps.user_id = viralit.host_id
LEFT JOIN VIRALITY.HOST h ON h.USER_ID = viralit.HOST_ID AND IS_SUSPICIOUS = false AND HAS_TRANSFERRED = true
WHERE 1 = 1
AND rank = 1 -- only latest NPS
AND viralit.count_signups < 50 -- to remove "Super inviters"
GROUP BY 1
order by nps;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment