Query editor
-- ============================================-- DIAGNOSTIC QUERY - FIND THE ANOMALIES FIRST-- ============================================-- Run this first to identify the problematic months/*SELECTmonth_year,chain_name,total_revenue,transaction_count,total_revenue / NULLIF(transaction_count, 0) as revenue_per_txFROM dune.odostreasury.dataset_total_revenueWHEREchain_name != '*** MONTHLY TOTAL ***'AND total_revenue > 1000000 -- Find unusually high revenuesORDER BY total_revenue DESCLIMIT 20*/-- ============================================-- MAIN QUERY - MONTHLY REVENUE WITH ANOMALY FILTERS-- ============================================WITH revenue_stats AS (-- Calculate statistics to identify outliersSELECTAVG(total_revenue) as avg_revenue,STDDEV(total_revenue) as std_revenue,APPROX_PERCENTILE(total_revenue, 0.95) as p95_revenue,APPROX_PERCENTILE(total_revenue, 0.99) as p99_revenueFROM dune.odostreasury.dataset_total_revenueWHEREchain_name != '*** MONTHLY TOTAL ***'AND month_year NOT IN ('1969-12', '2025-03', '2025-04') -- Exclude known bad monthsAND total_revenue > 0AND total_revenue < 1000000 -- Reasonable upper bound),filtered_data AS (SELECTd.month_year as month,d.chain_name as chain,d.total_revenue as original_revenue,d.transaction_count,-- Cap extreme values at 99th percentileCASEWHEN d.total_revenue > (SELECT p99_revenue * 10 FROM revenue_stats)THEN (SELECT p99_revenue FROM revenue_stats)ELSE d.total_revenueEND as revenueFROM dune.odostreasury.dataset_total_revenue dWHEREd.chain_name != '*** MONTHLY TOTAL ***'AND d.month_year != '1969-12' -- Invalid dateAND d.total_revenue > 0-- Filter out extreme outliers (likely data errors)AND d.total_revenue < 10000000 -- 10M cap-- Filter out months with suspiciously high revenue per transactionAND (d.total_revenue / NULLIF(d.transaction_count, 0)) < 10000