Query editor
with monthly_active as (SELECT date_trunc(casewhen '{{Timeframe}}' = 'Daily' then 'day'when '{{Timeframe}}' = 'Weekly' then 'week'when '{{Timeframe}}' = 'Monthly' then 'month' end ,block_time) as time, APPROX_DISTINCT(address) as active_addressFROM bitcoin.inputswhere date_trunc('day',block_time)>=(casewhen '{{Timeframe}}' = 'Daily' then date(now() - interval '1' year)when '{{Timeframe}}' = 'Weekly' then date(now() - interval '2' year)when '{{Timeframe}}' = 'Monthly' then date('2013-01-01')end)group by 1),price as (select date_trunc('day',minute) as day, avg(price) as pricefrom prices.usdwhere contract_address is null and symbol = 'BTC'and date_trunc('day',minute)>=(casewhen '{{Timeframe}}' = 'Daily' then date(now() - interval '1' year)when '{{Timeframe}}' = 'Weekly' then date(now() - interval '2' year)when '{{Timeframe}}' = 'Monthly' then date('2013-01-01')end)group by 1),monthly_vol as (select date_trunc(casewhen '{{Timeframe}}' = 'Daily' then 'day'when '{{Timeframe}}' = 'Weekly' then 'week'when '{{Timeframe}}' = 'Monthly' then 'month' end ,a.day) as time,sum(volume*price) as volume from (select date_trunc('day',block_date) as day, sum(output_value) as volumefrom bitcoin.transactionswhere date_trunc('day',block_date)>=(casewhen '{{Timeframe}}' = 'Daily' then date(now() - interval '1' year)when '{{Timeframe}}' = 'Weekly' then date(now() - interval '2' year)when '{{Timeframe}}' = 'Monthly' then date('2013-01-01')end)group by 1)aleft join price bon a.day=b.daygroup by 1)select a.time AS datetime, volume, active_addressfrom monthly_vol aleft join monthly_active bon a.time = b.timewhere volume is not null