Query editor
WITH daily_closing_prices AS (SELECTDATE_TRUNC('day', timestamp) AS day,price,-- Rank the hours within each day in descending order (latest hour gets rn = 1)ROW_NUMBER() OVER (PARTITION BY DATE_TRUNC('day', timestamp) ORDER BY timestamp DESC) AS rnFROM prices.hourWHERE blockchain = 'ethereum'AND contract_address = 0xa12cc123ba206d4031d1c7f6223d1c2ec249f4f3AND timestamp >= TIMESTAMP '2026-02-02 13:00:00'),monthly_twap AS (SELECTDATE_FORMAT(DATE_TRUNC('month', day), '%Y-%m') AS month,AVG(price) AS daily_close_twap_usd,COUNT(price) AS days_in_monthFROM daily_closing_pricesWHERE rn = 1 -- Filters for only the last price of each dayGROUP BY 1)-- 1. Hardcoded row for JanuarySELECTDATE_FORMAT(DATE_TRUNC('month', TIMESTAMP '2026-01-01 00:00:00'), '%Y-%m') AS month,0.0 AS daily_close_twap_usdUNION ALL-- 2. The rest of your calculated monthsSELECT month, daily_close_twap_usdFROM monthly_twap-- 3. Sort everything chronologically so January appears firstORDER BY month ASC;