Query editor
/* ============================================================================Q5c · Growth-push attribution — before vs after, equal windows----------------------------------------------------------------------------Compares average daily protocol revenue in the {{lookback_days}} days before{{campaign_start}} with the same number of days from the start (or fewer, ifthe push is younger than that). Only complete days are used after the start.Lift is a simple before/after difference: it does not control for marketconditions (ETH price, chain-wide activity), so read it alongside theper-token table for which launches moved.========================================================================== */WITH with_total AS ( -- per protocol and Total in one pass over the reconciliation querySELECT day, coalesce(protocol, 'Total') AS protocol,sum(computed_revenue_usd) AS revenue_usd, sum(computed_revenue_eth) AS revenue_ethFROM query_9105610WHERE protocol IN ('Tsunami', 'Calamari')GROUP BY GROUPING SETS ((day, protocol), (day))),bounds AS (SELECT date_trunc('day', TIMESTAMP '{{campaign_start}}') AS start_day,least(date_trunc('day', TIMESTAMP '{{campaign_start}}') + INTERVAL '{{lookback_days}}' DAY,date_trunc('day', now())) AS after_end -- exclude today's partial day)SELECT w.protocol,count_if(w.day < b.start_day) AS days_before,round(avg(CASE WHEN w.day < b.start_day THEN w.revenue_usd END), 2) AS avg_daily_revenue_usd_before,count_if(w.day >= b.start_day) AS days_after,round(avg(CASE WHEN w.day >= b.start_day THEN w.revenue_usd END), 2) AS avg_daily_revenue_usd_after,round(100 * (avg(CASE WHEN w.day >= b.start_day THEN w.revenue_usd END)/ nullif(avg(CASE WHEN w.day < b.start_day THEN w.revenue_usd END), 0) - 1), 1) AS lift_pct,round(sum(CASE WHEN w.day >= b.start_day THEN w.revenue_usd END), 2) AS revenue_usd_since_start,round(sum(CASE WHEN w.day >= b.start_day THEN w.revenue_eth END), 6) AS revenue_eth_since_start,round({{foundation_share_pct}} / 100.0 * sum(CASE WHEN w.day >= b.start_day THEN w.revenue_usd END), 2) AS foundation_share_usd_since_startFROM with_total wCROSS JOIN bounds bWHERE w.day >= b.start_day - INTERVAL '{{lookback_days}}' DAYAND w.day < b.after_endGROUP BY 1ORDER BY CASE w.protocol WHEN 'Total' THEN 0 WHEN 'Tsunami' THEN 1 ELSE 2 END