Query editor
with all_ohm_trades as (selectdate_trunc('week',block_date) as week, CASEWHEN token_sold_address = 0x64aa3364f17a4d01c6f1751fd97c2bd3d7e7f1d5 THEN 'sell'WHEN token_bought_address = 0x64aa3364f17a4d01c6f1751fd97c2bd3d7e7f1d5 THEN 'buy'END as action, token_bought_symbol, token_sold_symbol, token_pair, token_bought_amount, token_sold_amount, amount_usd, token_bought_address, token_sold_address, project_contract_address, tx_hash, tx_from, tx_to, evt_indexfrom dex.tradeswhere block_date > cast('2022-11-22' as timestamp) and token_bought_address = 0x64aa3364F17a4D01c6f1751Fd97C2BD3D7e7f1D5or block_date > cast('2022-11-22' as timestamp) and token_sold_address = 0x64aa3364F17a4D01c6f1751Fd97C2BD3D7e7f1D5),txs_with_result as (selectweek, action, CASEwhen action = 'sell' then -(amount_usd)when action = 'buy' then amount_usdEND as result, tx_hash, token_pairfrom all_ohm_trades),distinct_txns as (selectdistinct tx_hash, sum(result) as difference, max(week) as weekfrom txs_with_resultgroup by 1),buys as (selectweek, sum(difference) as sum_boughtfrom distinct_txnswhere difference > 0group by 1),sells as (selectweek, -sum(difference) as sum_soldfrom distinct_txns