Query editor
with cohort_base as (select *from query_5824720),cohort_with_index as (SELECTtrader,block_time,amount_usd,format_datetime(first_buy, 'YYYY-MM') AS cohort_date,(YEAR(block_time) - YEAR(first_buy))*12 + (MONTH(block_time) - MONTH(first_buy)) +1 as cohort_indexFROM (SELECTtrader,Min(block_time)OVER(PARTITION BY trader) as first_buy,block_time,amount_usdFROM cohort_base) a),cohort_table as (SELECTcohort_date,cohort_index,COUNT(distinct trader) as trader_count,SUM(amount_usd) as volumeFROM cohort_with_indexGroup by 1,2)SELECTcohort_date,SUM(CASE WHEN cohort_index = 1 then volume else 0 end) as "0",SUM(CASE WHEN cohort_index = 2 then volume else 0 end) as "1",SUM(CASE WHEN cohort_index = 3 then volume else 0 end) as "2",SUM(CASE WHEN cohort_index = 4 then volume else 0 end) as "3",SUM(CASE WHEN cohort_index = 5 then volume else 0 end) as "4",SUM(CASE WHEN cohort_index = 6 then volume else 0 end) as "5",SUM(CASE WHEN cohort_index = 7 then volume else 0 end) as "6",SUM(CASE WHEN cohort_index = 8 then volume else 0 end) as "7",SUM(CASE WHEN cohort_index = 9 then volume else 0 end) as "8",SUM(CASE WHEN cohort_index = 10 then volume else 0 end) as "9",SUM(CASE WHEN cohort_index = 11 then volume else 0 end) as "10",SUM(CASE WHEN cohort_index = 12 then volume else 0 end) as "11",SUM(CASE WHEN cohort_index = 13 then volume else 0 end) as "12"FROM cohort_tableGROUP BY 1Order by 1 asc