Query editor
WITHtransfers AS (SELECTDAY,address,token_address,SUM(amount)/1e18 AS amount /* Net inflow or outflow per day */FROM(SELECTDATE_TRUNC('day', evt_block_time) AS DAY,"to" AS address,tr.contract_address AS token_address,CAST(value AS int256) AS amountFROMerc20_ethereum.evt_Transfer AS trWHEREcontract_address = 0xBe9895146f7AF43049ca1c1AE358B0541Ea49704UNION ALLSELECTDATE_TRUNC('day', evt_block_time) AS DAY,"from" AS address,tr.contract_address AS token_address,- CAST(value AS int256) AS amountFROMerc20_ethereum.evt_Transfer AS trWHEREcontract_address = 0xBe9895146f7AF43049ca1c1AE358B0541Ea49704) AS tGROUP BY1,2,3),balances_with_gap_days AS (SELECTt.day,address,SUM(amount) OVER (PARTITION BYaddressORDER BYt.day) AS balance,/* balance per day with a transfer */ LEAD(DAY, 1, CURRENT_TIMESTAMP) OVER (PARTITION BYaddressORDER BYt.day) AS next_day /* the day after a day with a transfer */FROMtransfers AS t),days AS (selectcast(date_column as timestamp) as dayfrom(valuessequence(cast('2022-01-01' as timestamp),cast(date_trunc('day', current_timestamp) as timestamp),