Query editor
WITH transfers AS (SELECTDAY,address,token_address,sum(amount) AS amountFROM (SELECTdate_trunc('day', evt_block_time) AS DAY,"to" AS address,contract_address AS token_address,cast(value as bigint) AS amountFROM erc20_ethereum.evt_TransferWHERE contract_address = 0xa735a3af76cc30791c61c10d585833829d36cbe0UNION ALLSELECTdate_trunc('day', evt_block_time) AS DAY,"from" AS address,contract_address AS token_address,-cast(value as bigint) AS amountFROM erc20_ethereum.evt_TransferWHERE contract_address = 0xa735a3af76cc30791c61c10d585833829d36cbe0) tGROUP BY 1, 2, 3),balances_with_gap_days AS (SELECTt.day as t_day,address,SUM(amount) OVER (PARTITION BY address ORDER BY t.day) AS balance,lead(DAY, 1, now()) OVER (PARTITION BY address ORDER BY t.day) AS next_dayFROM transfers t),days AS (SELECTdFROMUNNEST(sequence(date_trunc('day', CAST(NOW() AS TIMESTAMP) - interval '12' month), CAST(NOW() AS TIMESTAMP), interval '1' day)) as td1(d)),balance_all_days AS (SELECTd,address,SUM(balance) AS balanceFROM balances_with_gap_daysINNER JOIN days ON t_day <= dAND d < next_dayGROUP BY 1, 2ORDER BY 1, 2)SELECTd AS "Date",COUNT(address) AS "Holders",COUNT(address) - lag(COUNT(address)) OVER (ORDER BY d) AS "Change"FROM balance_all_days bWHERE balance > 0