Query editor
-- Laso cohort dollar retention-- Shows the last 16 complete monthly cohorts (rolls forward as data is refreshed).-- Deposit volume of each monthly cohort in month N as % of its month-0 volume (net revenue-- retention analogue; can exceed 100%). Users only. Complete months only.-- Source: Laso Deposits Base (SGV), dune.socialgraphventures.result_laso_deposits_base_sgv.WITH lim AS (SELECT MAX(data_through) AS data_through,CAST(date_trunc('month', MAX(data_through) + INTERVAL '1' DAY) AS date) AS first_open_monthFROM dune.socialgraphventures.result_laso_deposits_base_sgv),mau AS (-- complete months onlySELECT month, sender, SUM(amount_usd) AS volumeFROM dune.socialgraphventures.result_laso_deposits_base_sgvWHERE sender_type = 'user'AND month < (SELECT first_open_month FROM lim)GROUP BY 1, 2),first_m AS (SELECT sender, MIN(month) AS first_month FROM mau GROUP BY 1),decorated AS (SELECT f.first_month, m.month, m.sender, m.volume,CAST(date_diff('month', f.first_month, m.month) AS integer) AS months_since_firstFROM mau m JOIN first_m f ON f.sender = m.sender),cohorts AS (SELECT first_month, months_since_first, SUM(volume) AS cohort_volumeFROM decorated GROUP BY 1, 2),baseline AS (SELECT first_month, cohort_volume AS baseline_volume FROM cohorts WHERE months_since_first = 0),base AS (SELECT c.first_month AS cohort, b.baseline_volume,MAP_AGG(c.months_since_first + 1, ROUND(100.0 * c.cohort_volume / NULLIF(b.baseline_volume, 0), 1)) AS kFROM cohorts c JOIN baseline b ON b.first_month = c.first_monthGROUP BY 1, 2)SELECTSUBSTRING(CAST(cohort AS varchar), 1, 10) AS cohort_month,ROUND(baseline_volume, 0) AS month_0_volume,TRY(k[1]) AS month_0,TRY(k[2]) AS month_1,TRY(k[3]) AS month_2,TRY(k[4]) AS month_3,TRY(k[5]) AS month_4,TRY(k[6]) AS month_5,TRY(k[7]) AS month_6,TRY(k[8]) AS month_7,TRY(k[9]) AS month_8,TRY(k[10]) AS month_9,TRY(k[11]) AS month_10,TRY(k[12]) AS month_11,TRY(k[13]) AS month_12,TRY(k[14]) AS month_13,TRY(k[15]) AS month_14,TRY(k[16]) AS month_15FROM baseWHERE cohort >= date_add('month', -16, (SELECT first_open_month FROM lim)) -- last 16 complete monthly cohorts