Query editor
with daily as (SELECT DATE_TRUNC('day', evt_block_time) as "Date", maker as "User"FROM predict_bnb.ctfexchange_evt_orderfilled -- single-outcome markets makersUNION ALLSELECT DATE_TRUNC('day', evt_block_time) as "Date", takerFROM predict_bnb.ctfexchange_evt_orderfilled -- single-outcome markets takersUNION ALLSELECT DATE_TRUNC('day', evt_block_time) as "Date", makerFROM predict_bnb.negriskctfexchange_evt_orderfilled -- multi-outcome markets makersUNION ALLSELECT DATE_TRUNC('day', evt_block_time) as "Date", takerFROM predict_bnb.negriskctfexchange_evt_orderfilled -- multi-outcome markets takers),oldandnew as (SELECT "Date", new_users as "New", (unique_users - new_users) as "Old"FROM (SELECT sq."Date", COUNT(*) AS new_usersFROM (SELECT "User" as unique_users, MIN("Date") AS "Date"FROM dailyGROUP BY 1ORDER BY 1) sqGROUP BY 1) ssq LEFT JOIN (SELECT "Date" AS "Date", COUNT(DISTINCT "User") AS unique_usersFROM dailyGROUP BY 1ORDER BY 1) t2 USING("Date")ORDER BY 1 DESC),firstseen as (SELECT MIN("Date") AS "Date", "User" as unique_users FROM dailyGROUP BY 2)SELECT * FROM (SELECT DISTINCT f."Date", "New", "Old",COUNT(unique_users) OVER (ORDER BY f."Date") as "Cumulative Unique Users"FROM firstseen fINNER JOIN oldandnew o ON f."Date" = o."Date")WHERE "Date" >= CURRENT_DATE - INTERVAL '2' MONTHAND "Date" < CURRENT_DATE -- drop the incomplete current dayORDER BY "Date" DESC