Query editor
-- Long format: one row per (day, wallet). Date-spined across the full range so-- quiet days render as zero rather than as gaps in the chart.-- Filter with the {{wallet}} parameter.WITH src AS (SELECT *FROM dune.talma.result_wallet_flow_transfersWHERE NOT is_internalAND ('{{wallet}}' = 'All wallets' OR wallet_label = '{{wallet}}')),bounds AS (SELECT MIN(block_date) AS d0, MAX(block_date) AS d1 FROM src),spine AS (SELECT d AS block_dateFROM boundsCROSS JOIN UNNEST(SEQUENCE(d0, d1, INTERVAL '1' DAY)) AS t(d)),wallet_list AS (SELECT DISTINCT wallet_label FROM src),grid AS (SELECT s.block_date, w.wallet_labelFROM spine s CROSS JOIN wallet_list w),daily AS (SELECTblock_date,wallet_label,COUNT(DISTINCT tx_hash) AS txns,COUNT(DISTINCT CASE WHEN direction = 'inflow' THEN tx_hash END) AS inflow_txns,COUNT(DISTINCT CASE WHEN direction = 'outflow' THEN tx_hash END) AS outflow_txns,COALESCE(SUM(amount_usd) FILTER (WHERE direction = 'inflow'), 0) AS inflow_usd,COALESCE(SUM(amount_usd) FILTER (WHERE direction = 'outflow'), 0) AS outflow_usd,COUNT(DISTINCT counterparty) AS counterpartiesFROM srcGROUP BY block_date, wallet_label)SELECTg.block_date,g.wallet_label,COALESCE(d.txns, 0) AS txns,COALESCE(d.inflow_txns, 0) AS inflow_txns,COALESCE(d.outflow_txns, 0) AS outflow_txns,COALESCE(d.inflow_usd, 0) AS inflow_usd,-COALESCE(d.outflow_usd, 0) AS outflow_usd_neg,COALESCE(d.inflow_usd, 0) - COALESCE(d.outflow_usd, 0) AS net_usd,COALESCE(d.counterparties, 0) AS counterparties,SUM(COALESCE(d.txns, 0)) OVER (PARTITION BY g.wallet_label ORDER BY g.block_date) AS cum_txns,SUM(COALESCE(d.inflow_usd, 0)) OVER (PARTITION BY g.wallet_label ORDER BY g.block_date) AS cum_inflow_usd,SUM(COALESCE(d.outflow_usd, 0)) OVER (PARTITION BY g.wallet_label ORDER BY g.block_date) AS cum_outflow_usd,SUM(COALESCE(d.inflow_usd, 0) - COALESCE(d.outflow_usd, 0))OVER (PARTITION BY g.wallet_label ORDER BY g.block_date) AS cum_net_usdFROM grid gLEFT JOIN daily dON d.block_date = g.block_dateAND d.wallet_label = g.wallet_labelORDER BY g.block_date, g.wallet_label