New churned deals model

This commit is contained in:
Joaquin Ossa 2025-03-06 14:57:23 +01:00
parent 089a1c37bd
commit 1245a88867
2 changed files with 259 additions and 13 deletions

View file

@ -1,5 +1,8 @@
-- HubSpot id_stage for live deals
{% set live_stage = "Live" %}
with
stg_hubspot__deals as (select * from {{ ref("stg_hubspot__deals") }}),
int_hubspot__deal as (select * from {{ ref("int_hubspot__deal") }}),
int_monthly_aggregated_metrics_history_by_deal_by_time_window as (
select *
from {{ ref("int_monthly_aggregated_metrics_history_by_deal_by_time_window") }}
@ -8,18 +11,98 @@ with
int_core__accommodation as (select * from {{ ref("int_core__accommodation") }})
select
d.id_deal,
m.main_deal_name,
m.client_type,
m.has_active_pms,
m.active_pms_list,
d.cancellation_date_utc,
date_trunc('month', d.cancellation_date_utc) as churn_month,
from stg_hubspot__deals d
left join
int_monthly_aggregated_metrics_history_by_deal_by_time_window m
on d.id_deal = m.id_deal
and date_trunc('month', d.cancellation_date_utc) = date_trunc('month', m.date)
left join int_core__user_host uh on d.id_deal = uh.id_deal
d.live_date_utc,
case
when d.deal_hubspot_stage = '{{ live_stage }}' then true else false
end as is_currently_active,
mam.main_deal_name,
mam.client_type,
mam.has_active_pms,
mam.active_pms_list,
mam.main_billing_country_iso_3_per_deal,
sum(
case
when mam.time_window = 'Previous 12 months'
then mam.total_revenue_in_gbp
else 0
end
) as total_revenue_in_gbp_previous_12_months,
sum(
case
when mam.time_window = 'Previous 6 months'
then mam.total_revenue_in_gbp
else 0
end
) as total_revenue_in_gbp_previous_6_months,
sum(
case
when mam.time_window = 'Previous 3 months'
then mam.total_revenue_in_gbp
else 0
end
) as total_revenue_in_gbp_previous_3_months,
sum(
case
when mam.time_window = 'Previous month' then mam.total_revenue_in_gbp else 0
end
) as total_revenue_in_gbp_previous_month,
sum(
case
when mam.time_window = 'Previous 12 month'
then mam.revenue_retained_post_resolutions_in_gbp
else 0
end
) as revenue_retained_post_resolutions_in_gbp_previous_12_months,
sum(
case
when mam.time_window = 'Previous 6 month'
then mam.revenue_retained_post_resolutions_in_gbp
else 0
end
) as revenue_retained_post_resolutions_in_gbp_previous_6_months,
sum(
case
when mam.time_window = 'Previous 3 month'
then mam.revenue_retained_post_resolutions_in_gbp
else 0
end
) as revenue_retained_post_resolutions_in_gbp_previous_3_months,
sum(
case
when mam.time_window = 'Previous month'
then mam.revenue_retained_post_resolutions_in_gbp
else 0
end
) as revenue_retained_post_resolutions_in_gbp_previous_month,
sum(
case
when mam.time_window = 'Previous 12 month' then mam.created_bookings else 0
end
) as created_bookings_previous_12_months,
sum(
case
when mam.time_window = 'Previous 6 month' then mam.created_bookings else 0
end
) as created_bookings_previous_6_months,
sum(
case
when mam.time_window = 'Previous 3 month' then mam.created_bookings else 0
end
) as created_bookings_previous_3_months,
sum(
case
when mam.time_window = 'Previous month' then mam.created_bookings else 0
end
) as created_bookings_previous_month,
count(distinct a.id_accommodation) as number_of_accommodations
from int_hubspot__deal d
inner join
int_monthly_aggregated_metrics_history_by_deal_by_time_window mam
on d.id_deal = mam.id_deal
and date_trunc('month', d.cancellation_date_utc) = date_trunc('month', mam.date)
inner join
int_core__user_host uh on d.id_deal = uh.id_deal and uh.is_test_account = false
left join int_core__accommodation a on uh.id_user_host = a.id_user_host
where d.cancellation_date_utc is not null
group by 1, 2, 3, 4, 5, 6, 7, 8, 9

View file

@ -2745,3 +2745,166 @@ models:
Relative difference between the current year YTD and the YTD target,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.
- name: int_monthly_churned_deals
description: |
"Model containing deals that have churned according to our data in HubSpot.
It contains the main metrics of revenue for different time windows from
the cancellation month.
There might be some cases where the churned deal is reactivated, this will
be reflected in the field 'is_currently_active'."
columns:
- name: id_deal
data_type: character varying
description:
"Main identifier of the B2B clients. A Deal can have multiple Hosts.
A Host can have only 1 Deal or no Deal at all. This field can be null."
data_tests:
- not_null
- name: cancellation_date_utc
data_type: date
description: "Date when the deal was offboarded according to
Hubspot."
data_tests:
- not_null
- name: live_date_utc
data_type: date
description: "Date when the deal went live according to
Hubspot. It can be null"
- name: is_currently_active
data_type: boolean
description: "Flag indicating if the deal has reactivated
after the churn."
- name: main_deal_name
data_type: string
description: |
Main name for this ID deal.
data_tests:
- not_null
- name: client_type
data_type: string
description: |
Type of client. It can be either PLATFORM or API.
data_tests:
- not_null
- accepted_values:
values:
- PLATFORM
- API
- name: has_active_pms
data_type: boolean
description: |
Does the deal have an active associated PMS.
data_tests:
- not_null
- name: active_pms_list
data_type: string
description: |
Name of the active PMS associated with the deal. It can have more than
one PMS associated with it. It can be null if it doesn't have any PMS associated.
- name: main_billing_country_iso_3_per_deal
data_type: string
description: |
ISO 3166-1 alpha-3 main country code in which the Deal is billed.
In some cases it's null.
- name: total_revenue_in_gbp_previous_12_months
data_type: numeric
description: |
"Total revenue in GBP generated by the deal for the 12 months preceding
the cancellation month. This considers the revenue from the full 12-month
period before the month in which the cancellation occurs."
- name: total_revenue_in_gbp_previous_6_months
data_type: numeric
description: |
"Total revenue in GBP generated by the deal for the 6 months preceding
the cancellation month. This considers the revenue from the full 6-month
period before the month in which the cancellation occurs."
- name: total_revenue_in_gbp_previous_3_months
data_type: numeric
description: |
"Total revenue in GBP generated by the deal for the 3 months preceding
the cancellation month. This considers the revenue from the full 3-month
period before the month in which the cancellation occurs."
- name: total_revenue_in_gbp_previous_month
data_type: numeric
description: |
"Total revenue in GBP generated by the deal for the month preceding
the cancellation month. This considers the revenue from the full month
before the month in which the cancellation occurs."
- name: revenue_retained_post_resolutions_in_gbp_previous_12_months
data_type: numeric
description: |
"Total amount of revenue in GBP retained by the deal
post waiver payouts and resolution payouts in GBP for the 12 months preceding
the cancellation month. This considers the revenue from the full 12-month
period before the month in which the cancellation occurs."
- name: revenue_retained_post_resolutions_in_gbp_previous_6_months
data_type: numeric
description: |
"Total amount of revenue in GBP retained by the deal
post waiver payouts and resolution payouts in GBP for the 6 months preceding
the cancellation month. This considers the revenue from the full 6-month
period before the month in which the cancellation occurs."
- name: revenue_retained_post_resolutions_in_gbp_previous_3_months
data_type: numeric
description: |
"Total amount of revenue in GBP retained by the deal
post waiver payouts and resolution payouts in GBP for the 3 months preceding
the cancellation month. This considers the revenue from the full 3-month
period before the month in which the cancellation occurs."
- name: revenue_retained_post_resolutions_in_gbp_previous_month
data_type: numeric
description: |
"Total amount of revenue in GBP retained by the deal
post waiver payouts and resolution payouts in GBP for the month preceding
the cancellation month. This considers the revenue from the full month
before the month in which the cancellation occurs."
- name: created_bookings_previous_12_months
data_type: numeric
description: |
"Total number of bookings created by the deal for the 12 months preceding
the cancellation month. This considers the bookings from the full 12-month
period before the month in which the cancellation occurs."
- name: created_bookings_previous_6_months
data_type: numeric
description: |
"Total number of bookings created by the deal for the 6 months preceding
the cancellation month. This considers the bookings from the full 6-month
period before the month in which the cancellation occurs."
- name: created_bookings_previous_3_months
data_type: numeric
description: |
"Total number of bookings created by the deal for the 3 months preceding
the cancellation month. This considers the bookings from the full 3-month
period before the month in which the cancellation occurs."
- name: created_bookings_previous_month
data_type: numeric
description: |
"Total number of bookings created by the deal for the month preceding
the cancellation month. This considers the bookings from the full month
before the month in which the cancellation occurs."
- name: number_of_accommodations
data_type: bigint
description: |
"Total number of accommodations associated with the deal."33