Updated 2022-12-15
    with t1 as (
    SELECT
    distinct to_address,
    label_type as name,
    trunc(block_timestamp,'{{granularity}}') as date,
    count(distinct tx_hash) as txs,
    count(distinct from_address) as active_users
    from polygon.core.fact_transactions x
    join polygon.core.dim_labels y on x.to_address=y.address
    where block_timestamp>=CURRENT_DATE- INTERVAL '{{period}}'
    group by 1,2,3 order by 3 asc, 2
    )
    SELECT
    date,case when txs<1000 or active_users<1000 then 'Others' else name end as contract,
    sum(txs) as txss,
    sum(txss) over (partition by contract order by date) as cum_txs,
    sum(active_users) as active_userss,
    sum(active_userss) over (partition by contract order by date) as cum_active_users
    from t1
    group by 1,2 order by 1 asc, 2
    Run a query to Download Data