Updated logic of model
This commit is contained in:
parent
b063454409
commit
261c6d3c49
2 changed files with 21 additions and 10 deletions
|
|
@ -7,7 +7,7 @@ with
|
||||||
),
|
),
|
||||||
monthly_revenue_per_number_of_properties as (
|
monthly_revenue_per_number_of_properties as (
|
||||||
select
|
select
|
||||||
date_trunc('month', m.date)::date as metric_month,
|
m.date as metric_month,
|
||||||
coalesce(
|
coalesce(
|
||||||
d.main_billing_country_iso_3_per_deal, 'global'
|
d.main_billing_country_iso_3_per_deal, 'global'
|
||||||
) as main_billing_country_iso_3,
|
) as main_billing_country_iso_3,
|
||||||
|
|
@ -22,19 +22,20 @@ with
|
||||||
on m.id_deal = d.id_deal
|
on m.id_deal = d.id_deal
|
||||||
and date_trunc('month', m.date) >= d.effective_deal_start_month
|
and date_trunc('month', m.date) >= d.effective_deal_start_month
|
||||||
and date_trunc('month', m.date)
|
and date_trunc('month', m.date)
|
||||||
<= coalesce(d.effective_deal_cancellation_month, '2099-01-01')
|
<= coalesce(d.hubspot_deal_cancellation_month, '2099-01-01')
|
||||||
and date_trunc('month', m.date)::date <> date_trunc('month', now())::date
|
and date_trunc('month', m.date)::date <> date_trunc('month', now())::date
|
||||||
where d.hubspot_listing_segmentation <> 'UNSET'
|
where d.hubspot_listing_segmentation <> 'UNSET'
|
||||||
group by
|
group by
|
||||||
rollup (
|
rollup (
|
||||||
date_trunc('month', m.date)::date,
|
m.date,
|
||||||
d.hubspot_listing_segmentation,
|
d.hubspot_listing_segmentation,
|
||||||
d.main_billing_country_iso_3_per_deal
|
d.main_billing_country_iso_3_per_deal
|
||||||
)
|
)
|
||||||
having date_trunc('month', m.date)::date is not null
|
-- Exclude total date aggregation
|
||||||
|
having m.date is not null
|
||||||
)
|
)
|
||||||
select
|
select
|
||||||
(r.metric_month - interval '1 day')::date as date,
|
r.metric_month as date,
|
||||||
r.main_billing_country_iso_3,
|
r.main_billing_country_iso_3,
|
||||||
r.hubspot_listing_segmentation,
|
r.hubspot_listing_segmentation,
|
||||||
sum(coalesce(m.total_revenue_in_gbp, 0)) as total_revenue_in_gbp,
|
sum(coalesce(m.total_revenue_in_gbp, 0)) as total_revenue_in_gbp,
|
||||||
|
|
@ -44,8 +45,8 @@ select
|
||||||
from monthly_revenue_per_number_of_properties m
|
from monthly_revenue_per_number_of_properties m
|
||||||
inner join
|
inner join
|
||||||
monthly_revenue_per_number_of_properties r
|
monthly_revenue_per_number_of_properties r
|
||||||
on r.metric_month > m.metric_month
|
on r.metric_month >= m.metric_month
|
||||||
and r.metric_month <= m.metric_month + interval '12 months'
|
and r.metric_month < m.metric_month + interval '12 months'
|
||||||
and r.hubspot_listing_segmentation = m.hubspot_listing_segmentation
|
and r.hubspot_listing_segmentation = m.hubspot_listing_segmentation
|
||||||
and r.main_billing_country_iso_3 = m.main_billing_country_iso_3
|
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.metric_month, r.hubspot_listing_segmentation, r.main_billing_country_iso_3
|
||||||
|
|
|
||||||
|
|
@ -1714,12 +1714,22 @@ models:
|
||||||
each new deal. It is calculated by taking the total revenue generated by all
|
each new deal. It is calculated by taking the total revenue generated by all
|
||||||
active accounts over the last 12 months and dividing it by the number of active
|
active accounts over the last 12 months and dividing it by the number of active
|
||||||
months for each account."
|
months for each account."
|
||||||
|
|
||||||
|
data_tests:
|
||||||
|
- dbt_utils.unique_combination_of_columns:
|
||||||
|
combination_of_columns:
|
||||||
|
- date
|
||||||
|
- main_billing_country_iso_3
|
||||||
|
- hubspot_listing_segmentation
|
||||||
|
|
||||||
columns:
|
columns:
|
||||||
- name: date
|
- name: date
|
||||||
data_type: date
|
data_type: date
|
||||||
description: |
|
description: |
|
||||||
"Last date of the month for which the data is reported.
|
"Date representing the last day of the month. The metrics are calculated using data
|
||||||
It considers the data from the previous 12 months up to the date."
|
from the 12 months leading up to and including this date. Along with
|
||||||
|
`main_billing_country_iso_3` and `hubspot_listing_segmentation`, this field serves
|
||||||
|
as part of the primary key for the model."
|
||||||
data_tests:
|
data_tests:
|
||||||
- not_null
|
- not_null
|
||||||
- is_last_day_of_month
|
- is_last_day_of_month
|
||||||
|
|
@ -1727,7 +1737,7 @@ models:
|
||||||
- name: main_billing_country_iso_3
|
- name: main_billing_country_iso_3
|
||||||
data_type: text
|
data_type: text
|
||||||
description: |
|
description: |
|
||||||
"ISO 3166-1 alpha-3 main country code in which the Deals are billed"
|
"Main billing country code from ISO 3166"
|
||||||
data_tests:
|
data_tests:
|
||||||
- not_null
|
- not_null
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue