Found the issue that was excluding some deals

This commit is contained in:
Joaquin Ossa 2025-01-15 16:35:02 +01:00
parent 261c6d3c49
commit 5bf2fba4cf

View file

@ -1,13 +1,22 @@
with
deal_attributes as (
select *
select
id_deal,
coalesce(
main_billing_country_iso_3_per_deal, 'UNSET'
) as main_billing_country_iso_3_per_deal,
effective_deal_start_month,
hubspot_deal_cancellation_month,
coalesce(
hubspot_listing_segmentation, 'UNSET'
) as hubspot_listing_segmentation
from {{ ref("int_kpis__dimension_deals") }}
-- Exclude deals without live dates
where effective_deal_start_date_utc is not null
),
monthly_revenue_per_number_of_properties as (
select
m.date as metric_month,
m.date,
coalesce(
d.main_billing_country_iso_3_per_deal, 'global'
) as main_billing_country_iso_3,
@ -20,7 +29,8 @@ with
inner join
deal_attributes d
on m.id_deal = d.id_deal
and date_trunc('month', m.date) >= d.effective_deal_start_month
and date_trunc('month', m.date)
>= date_trunc('month', d.effective_deal_start_month)
and date_trunc('month', m.date)
<= coalesce(d.hubspot_deal_cancellation_month, '2099-01-01')
and date_trunc('month', m.date)::date <> date_trunc('month', now())::date
@ -35,7 +45,7 @@ with
having m.date is not null
)
select
r.metric_month as date,
r.date,
r.main_billing_country_iso_3,
r.hubspot_listing_segmentation,
sum(coalesce(m.total_revenue_in_gbp, 0)) as total_revenue_in_gbp,
@ -45,8 +55,8 @@ select
from monthly_revenue_per_number_of_properties m
inner join
monthly_revenue_per_number_of_properties r
on r.metric_month >= m.metric_month
and r.metric_month < m.metric_month + interval '12 months'
on r.date >= m.date
and r.date < m.date + interval '12 months'
and r.hubspot_listing_segmentation = m.hubspot_listing_segmentation
and r.main_billing_country_iso_3 = m.main_billing_country_iso_3
group by r.metric_month, r.hubspot_listing_segmentation, r.main_billing_country_iso_3
group by r.date, r.hubspot_listing_segmentation, r.main_billing_country_iso_3