Query editor
with tmp as (select date, concat(pool,' - ', asset) as market, t.is_stablecoin, sum(total_debt_usd) as total_debt_usd, sum(total_supplied_usd) as total_supplied_usd, avg(0.2 * (POW((1+last_full_utilization_rate/1e18),(365*86400)) - 1)) as borrow_apr, avg(round(total_debt_usd/total_supplied_usd * 0.2 * (POW((1+last_full_utilization_rate/1e18),(365*86400)) - 1),5)) as supply_aprfrom dune.vesu.result_vesu_v_2_update_context_daily_dataleft join query_6314086 t on lower(t.symbol) = lower(asset)where concat(pool,' - ',asset) in (select concat(pool,' - ',asset) from query_6256450 where "Borrowed ($)" > 0)and (CASEWHEN '{{period}}' = 'day' THEN trueWHEN '{{period}}' = 'week' THEN MOD(date_diff('day', current_date, date), 7) = 0ELSE CAST(date_format(date, '%d') AS INTEGER) = 1END)and date >= cast('2025-04-01' as date)group by 1,2,3)select date, market, total_debt_usd / total_supplied_usd as "Utilization", SUM(total_debt_usd) OVER (PARTITION BY date)/SUM(total_supplied_usd) OVER (PARTITION BY date) as "Avg Utilization - All Markets", SUM(case when is_stablecoin then total_debt_usd else 0 end) OVER (PARTITION BY date)/SUM(case when is_stablecoin then total_supplied_usd else 0 end) OVER (PARTITION BY date) as "Avg Utilization - Stablecoin Markets", borrow_apr, supply_aprfrom tmporder by 1 desc