Query editor
WITH MaxDate AS (SELECT MAX(CAST(event_date AS DATE)) AS max_dateFROM dune.lagunagames12_team.dataset_cu_daily_joust_name_qty),aggregatedData AS (SELECTevent_date,joust_name,SUM(joust_event_qty) AS num_joustsFROM dune.lagunagames12_team.dataset_cu_daily_joust_name_qtyWHERE CAST(event_date AS DATE) < (SELECT max_date FROM MaxDate)GROUP BY event_date, joust_name)SELECTcast(event_date as timestamp) as event_date,casewhen joust_name = 'BRACKET_PRE_ELO_LOW_STAKES_BRONZE' or joust_name = 'joust_matchmaker_queue_bracket_elo_bronze_ranked' then 'Bronze'when joust_name = 'BRACKET_PRE_ELO_MID_STAKES_SILVER' or joust_name = 'joust_matchmaker_queue_bracket_elo_silver_ranked' then 'Silver'when joust_name = 'BRACKET_PRE_ELO_HIGH_STAKES_GOLD' or joust_name = 'joust_matchmaker_queue_bracket_elo_gold_ranked' then 'Gold'end as joust_name,num_jousts--SUM(COALESCE(unim_to_sc, 0)) OVER (ORDER BY event_date) AS cumulative_unim_to_scFROM aggregatedDataORDER BY event_date DESClimit 60