Updated existing model with some new fields for churning report

This commit is contained in:
Joaquin Ossa 2025-03-06 17:12:32 +01:00
parent 24d13185eb
commit f8b551a75c
4 changed files with 52 additions and 311 deletions

View file

@ -13,6 +13,9 @@ with
and is_end_of_month = true
),
daily_deal_lifecycle as (select * from {{ ref("int_kpis__lifecycle_daily_deal") }}),
int_kpis__dimension_daily_accommodation as (
select * from {{ ref("int_kpis__dimension_daily_accommodation") }}
),
listings as (
select *
from {{ ref("int_kpis__agg_daily_listings") }}
@ -83,6 +86,9 @@ select
ikdd.main_deal_name,
ikdd.has_active_pms,
ikdd.active_pms_list,
coalesce(
dda.active_accommodations_per_deal_segmentation, 'UNSET'
) as active_accommodations_per_deal_segmentation,
ikdd.main_billing_country_iso_3_per_deal,
-- DEAL LIFECYCLE --
@ -160,8 +166,7 @@ select
as host_resolution_amount_paid_per_created_booking,
{{
return_capped_value(
"cast(host_resolutions.xero_host_resolution_payment_count as decimal)
/ created_bookings.created_bookings",
"cast(host_resolutions.xero_host_resolution_payment_count as decimal) / created_bookings.created_bookings",
-1,
1,
)
@ -228,17 +233,7 @@ select
) as revenue_retained_in_gbp,
{{
return_capped_value(
"nullif(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0),
0) /
nullif(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0),
0)",
"nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0), 0) / nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), 0)",
-1,
1,
)
@ -256,17 +251,7 @@ select
) as revenue_retained_post_resolutions_in_gbp,
{{
return_capped_value(
"nullif(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0)
+ coalesce(host_resolutions.xero_host_resolution_amount_paid_in_gbp, 0),
0) /
nullif(coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0),
0)",
"nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0) + coalesce(host_resolutions.xero_host_resolution_amount_paid_in_gbp, 0), 0) / nullif(coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), 0)",
-1,
1,
)
@ -279,6 +264,10 @@ left join
daily_deal_lifecycle
on d.date = daily_deal_lifecycle.date
and d.dimension_value = daily_deal_lifecycle.id_deal
left join
int_kpis__dimension_daily_accommodation as dda
on d.date = dda.date
and d.dimension_value = dda.id_deal
left join
created_bookings
on d.date = created_bookings.end_date

View file

@ -12,6 +12,7 @@ with
main_deal_name,
has_active_pms,
active_pms_list,
active_accommodations_per_deal_segmentation,
main_billing_country_iso_3_per_deal,
deal_lifecycle_state,
'All History' as time_window,
@ -126,6 +127,7 @@ with
main_deal_name,
has_active_pms,
active_pms_list,
active_accommodations_per_deal_segmentation,
main_billing_country_iso_3_per_deal,
deal_lifecycle_state,
'Previous 12 months' as time_window,
@ -225,6 +227,7 @@ with
main_deal_name,
has_active_pms,
active_pms_list,
active_accommodations_per_deal_segmentation,
main_billing_country_iso_3_per_deal,
deal_lifecycle_state,
'Previous 6 months' as time_window,
@ -324,6 +327,7 @@ with
main_deal_name,
has_active_pms,
active_pms_list,
active_accommodations_per_deal_segmentation,
main_billing_country_iso_3_per_deal,
deal_lifecycle_state,
'Previous 3 months' as time_window,
@ -423,6 +427,7 @@ with
main_deal_name,
has_active_pms,
active_pms_list,
active_accommodations_per_deal_segmentation,
main_billing_country_iso_3_per_deal,
deal_lifecycle_state,
'Previous month' as time_window,
@ -545,12 +550,14 @@ select
mabd.main_deal_name,
mabd.has_active_pms,
mabd.active_pms_list,
mabd.active_accommodations_per_deal_segmentation,
mabd.main_billing_country_iso_3_per_deal,
mabd.deal_lifecycle_state,
d.deal_hubspot_stage,
d.account_manager,
d.live_date_utc,
d.cancellation_date_utc,
d.cancellation_category,
-- Windowed metrics
coalesce(mabd.sum_created_bookings, 0) as created_bookings,

View file

@ -1,110 +0,0 @@
-- HubSpot id_stage for live deals
{% set live_stage = "Live" %}
with
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") }}
),
int_core__user_host as (select * from {{ ref("int_core__user_host") }}),
int_core__accommodation as (select * from {{ ref("int_core__accommodation") }})
select
d.id_deal,
extract(year from d.cancellation_date_utc) as cancellation_year,
extract(month from d.cancellation_date_utc) as cancellation_month,
d.cancellation_date_utc,
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, 10, 11

View file

@ -385,6 +385,22 @@ models:
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: active_accommodations_per_deal_segmentation
data_type: string
description: |
Segment value based on the number of listings booked in 12 months
for a given deal and date.
data_tests:
- not_null
- accepted_values:
values:
- "0"
- "01-05"
- "06-20"
- "21-60"
- "61+"
- "UNSET"
- name: main_billing_country_iso_3_per_deal
data_type: string
description: |
@ -1568,6 +1584,22 @@ models:
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: active_accommodations_per_deal_segmentation
data_type: string
description: |
Segment value based on the number of listings booked in 12 months
for a given deal and date.
data_tests:
- not_null
- accepted_values:
values:
- "0"
- "01-05"
- "06-20"
- "21-60"
- "61+"
- "UNSET"
- name: main_billing_country_iso_3_per_deal
data_type: string
description: |
@ -2745,180 +2777,3 @@ 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_year
data_type: integer
description: "Year when the deal was offboarded according to
Hubspot."
data_tests:
- not_null
- name: cancellation_month
data_type: integer
description: "Month when the deal was offboarded according to
Hubspot."
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