with
    int_kpis__agg_daily_deals as (
        select date, dimension_value as hubspot_listing_segmentation, new_deals
        from {{ ref("int_kpis__agg_daily_deals") }}
        where dimension = 'by_number_of_listings'
    ),
    number_of_listing_expected_mrr as (
        select
            mom.date,
            mom.dimension,
            mom.dimension_value,
            ad.new_deals as number_of_new_deals,
            mom.expected_mrr_per_deal * ad.new_deals as expected_mrr
        from {{ ref("int_monthly_onboarding_mrr_per_deal") }} mom
        left join
            int_kpis__agg_daily_deals ad
            on mom.date = ad.date
            and mom.dimension_value = ad.hubspot_listing_segmentation
        where mom.dimension = 'by_number_of_listings'
    )
select *
from number_of_listing_expected_mrr
union all
select
    date,
    'global' as dimension,
    'global' as dimension_value,
    sum(number_of_new_deals) as number_of_new_deals,
    sum(expected_mrr) as expected_mrr
from number_of_listing_expected_mrr
group by date
