Query editor
-- =====================================================-- PERIOD-OVER-PERIOD DASHBOARD QUERY-- Reads from the Private Activity MV, deduplicates volume, applies parameters-- =====================================================WITH params AS (SELECTCOALESCE(TRY_CAST('{{Start Date}}' AS TIMESTAMP), TIMESTAMP '2024-01-01 00:00:00') AS current_start,COALESCE(TRY_CAST('{{End Date}}' AS TIMESTAMP), CURRENT_TIMESTAMP) AS current_end),date_ranges AS (SELECTcurrent_start,current_end,current_start - (current_end - current_start) AS prev_start,current_start AS prev_endFROM params),base_data AS (-- 1. Read from the new MV and apply Date & Blockchain filtersSELECTday,blockchain,asset_type,operation,total_private_transactions,gross_deposit_amount,gross_deposit_usd,gross_withdrawal_usd,net_tvl_amount,net_tvl_usdFROM dune.igboweefe.result_private_activity_mvWHERE day >= (SELECT prev_start FROM date_ranges)AND day < (SELECT current_end FROM date_ranges)-- Supports 'All' in the Dune dashboard dropdown, or a specific chain (e.g., 'arbitrum')AND ('{{Blockchain}}' = 'All' OR blockchain = '{{Blockchain}}')),daily_aggregated AS (-- 2. DEDUPLICATION FIX: Proxy volumes are duplicated across operations in the MV.-- We SUM the transactions, but MAX the volumes per day to avoid double-counting.SELECTday,blockchain,asset_type,SUM(total_private_transactions) AS daily_txs,MAX(gross_deposit_amount) AS daily_deposit_native,MAX(gross_deposit_usd) AS daily_deposit_usd,MAX(gross_withdrawal_usd) AS daily_withdrawal_usd,MAX(net_tvl_amount) AS daily_tvl_native,MAX(net_tvl_usd) AS daily_tvl_usdFROM base_dataGROUP BY 1, 2, 3),flagged_data AS (-- 3. Assign Current vs Previous period flagsSELECTm.blockchain,m.asset_type,m.daily_txs,m.daily_deposit_native,m.daily_deposit_usd,