Query editor
-- =====================================================-- WEEKLY TRENDS (VOLUME & TRANSACTIONS PER CHAIN)-- Reads from Private Activity MV, applies parameters-- =====================================================WITH base_data AS (-- 1. Read from the new MV and apply Date & Blockchain filtersSELECTday,DATE_TRUNC('week', day) AS week_date,blockchain,asset_type,total_private_transactions,gross_deposit_usd,net_tvl_usdFROM dune.igboweefe.result_private_activity_mvWHERE day >= COALESCE(TRY_CAST('{{Start Date}}' AS TIMESTAMP), TIMESTAMP '2024-01-01 00:00:00')AND day < COALESCE(TRY_CAST('{{End Date}}' AS TIMESTAMP), CURRENT_TIMESTAMP)-- Supports 'All' in the Dune dashboard dropdown, or a specific chainAND ('{{Blockchain}}' = 'All' OR blockchain = '{{Blockchain}}')),daily_deduped AS (-- 2. DEDUPLICATION FIX: Volume is duplicated across operations (Mint vs Send).-- We SUM the transactions, but MAX the volumes per day to avoid double-counting.SELECTday,week_date,blockchain,asset_type,SUM(total_private_transactions) AS daily_txs,MAX(gross_deposit_usd) AS daily_deposit_usd,MAX(net_tvl_usd) AS daily_net_flow_usdFROM base_dataGROUP BY 1, 2, 3, 4),weekly_aggregated AS (-- 3. Roll up the deduplicated daily data into Weekly chunks per BlockchainSELECTweek_date,blockchain,SUM(daily_txs) AS weekly_transactions,SUM(daily_deposit_usd) AS weekly_deposit_usd,SUM(daily_net_flow_usd) AS weekly_net_flow_usdFROM daily_dedupedGROUP BY 1, 2)-- 4. Final output sorted for chartingSELECTCAST(week_date AS DATE) AS "WEEK",blockchain AS "BLOCKCHAIN",weekly_transactions AS "TRANSACTIONS",weekly_deposit_usd AS "DEPOSIT VOLUME (USD)",weekly_net_flow_usd AS "NET FLOW (USD)"FROM weekly_aggregatedORDER BY "WEEK" DESC, "DEPOSIT VOLUME (USD)" DESC;