Query editor
withtoken_transfer as (select *from query_3509451)SELECTdate_trunc('{{Time Period}}', time) AS time,tr.user AS user,SUM(amount_usd) AS net_usd_deposit,SUM(CASE WHEN "type" = 'deposit' THEN amount_usd ELSE 0 END) AS usd_deposit,SUM(CASE WHEN "type" = 'withdraw' THEN amount_usd ELSE 0 END) AS usd_withdraw,SUM(CASE WHEN "type" = 'deposit' THEN amount_usd ELSE -amount_usd END) AS usd_volume,COUNT(*) AS interaction_count,SUM(CASE WHEN "type" = 'deposit' THEN 1 ELSE 0 END) AS deposit_count,SUM(CASE WHEN "type" = 'withdraw' THEN 1 ELSE 0 END) AS withdraw_count,SUM(SUM(amount_usd)) OVER (PARTITION BY tr.user ORDER BY date_trunc('{{Time Period}}', time)) AS net_usd_deposit_cumulative,SUM(SUM(CASE WHEN "type" = 'deposit' THEN amount_usd ELSE 0 END)) OVER (PARTITION BY tr.user ORDER BY date_trunc('{{Time Period}}', time)) AS usd_deposit_cumulative,SUM(SUM(CASE WHEN "type" = 'withdraw' THEN amount_usd ELSE 0 END)) OVER (PARTITION BY tr.user ORDER BY date_trunc('{{Time Period}}', time)) AS usd_withdraw_cumulative,SUM(SUM(CASE WHEN "type" = 'deposit' THEN amount_usd ELSE -amount_usd END)) OVER (PARTITION BY tr.user ORDER BY date_trunc('{{Time Period}}', time)) AS usd_volume_cumulative,SUM(COUNT(*)) OVER (PARTITION BY tr.user ORDER BY date_trunc('{{Time Period}}', time)) AS interaction_count_cumulative,SUM(SUM(CASE WHEN "type" = 'deposit' THEN 1 ELSE 0 END)) OVER (PARTITION BY tr.user ORDER BY date_trunc('{{Time Period}}', time)) AS deposit_count_cumulative,SUM(SUM(CASE WHEN "type" = 'withdraw' THEN 1 ELSE 0 END)) OVER (PARTITION BY tr.user ORDER BY date_trunc('{{Time Period}}', time)) AS withdraw_count_cumulativeFROMtoken_transfer trWHEREdate_trunc('{{Time Period}}', time) >= CAST('{{Start Date}}' AS TIMESTAMP)GROUP BY1, 2ORDER BY1 DESC, 3 DESC