Query editor
WITH/*addresses AS (SELECT"to" AS adr {{Transaction_Value_Filter}}FROMerc20_ethereum.evt_Transfer AS trWHEREcontract_address = 0xf57e7e7c23978c3caec3c3548e3d615c346e79fflimit 100),*/transfers AS (SELECTDAY,address,token_address,SUM(amount) AS amount /* Net inflow or outflow of address per day */FROM(SELECTDATE_TRUNC('day', evt_block_time) AS DAY,"to" AS address,tr.contract_address AS token_address,cast(value as DOUBLE) AS amountFROMerc20_ethereum.evt_Transfer AS trWHEREcontract_address = 0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fFAND ( ('{{Transaction_Value_Filter}}' = 'Exclude_0_Value_Transactions' AND value > 0) OR ('{{Transaction_Value_Filter}}' != 'Exclude_0_Value_Transactions' AND value >= 0) )UNION ALLSELECTDATE_TRUNC('day', evt_block_time) AS DAY,"from" AS address,tr.contract_address AS token_address,- cast(value as DOUBLE) AS amountFROMerc20_ethereum.evt_Transfer AS trWHEREcontract_address = 0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF /* IMX Token */AND ( ('{{Transaction_Value_Filter}}' = 'Exclude_0_Value_Transactions' AND value > 0) OR ('{{Transaction_Value_Filter}}' != 'Exclude_0_Value_Transactions' AND value >= 0) )) AS tGROUP BY1,2,3),balances_with_gap_days AS (SELECTt.day,address,SUM(amount) OVER (PARTITION BY address ORDER BY t.day ) AS balance, /* balance per day with a transfer */LEAD(DAY, 1, CURRENT_TIMESTAMP) OVER ( PARTITION BY address ORDER BY t.day) AS next_day /* the day after a day with a transfer */FROM transfers AS t),days AS (SELECTDAYFROMUNNEST (SEQUENCE(TRY_CAST('2016-01-20' AS TIMESTAMP), CAST( CAST( CAST(DATE_TRUNC('day', CURRENT_TIMESTAMP) AS TIMESTAMP) AS TIMESTAMP ) AS TIMESTAMP ), INTERVAL '1' day ) ) AS _u (DAY)),