Merged PR 4395: Propagates business scope into Deal/Listing metrics
# Description Changes: * Propagates business scope, based on deal, for Deal and Listing metrics. This already handles the daily metric and the daily aggregation. * Modifies lifecycle_daily_deal to depend on dimension_deals and compute API segmentation. * Creates new metric: Live Deals, that includes New, Active and Reactivated. This will be needed for YTD/MTD overview. # Checklist - [X] The edited models and dependants run properly with production data. - [X] The edited models are sufficiently documented. - [X] The edited models contain PK tests, and I've ran and passed them. - [X] I have checked for DRY opportunities with other models and docs. - [X] I've picked the right materialization for the affected models. # Other - [ ] Check if a full-refresh is required after this PR is merged. Related work items: #27356
This commit is contained in:
parent
5382a9b32b
commit
d8a0bb07d3
6 changed files with 159 additions and 46 deletions
|
|
@ -8,7 +8,7 @@ with
|
|||
int_core__bookings as (select * from {{ ref("int_core__bookings") }}),
|
||||
int_core__user_host as (select * from {{ ref("int_core__user_host") }}),
|
||||
int_kpis__dimension_dates as (select * from {{ ref("int_kpis__dimension_dates") }}),
|
||||
int_hubspot__deal as (select * from {{ ref("int_hubspot__deal") }}),
|
||||
int_kpis__dimension_deals as (select * from {{ ref("int_kpis__dimension_deals") }}),
|
||||
|
||||
hubspot_deal_offboardings as (
|
||||
-- At the moment it's not possible to account for deal reactivation within
|
||||
|
|
@ -21,9 +21,9 @@ with
|
|||
-- discussing with our colleagues from sales / am teams. In this discussion
|
||||
-- period, the stage could be different than cancelled, but still not
|
||||
-- reactivated.
|
||||
select id_deal, cancellation_date_utc
|
||||
from int_hubspot__deal
|
||||
where cancellation_date_utc is not null
|
||||
select id_deal, hubspot_deal_cancellation_date_utc as cancellation_date_utc
|
||||
from int_kpis__dimension_deals
|
||||
where hubspot_deal_cancellation_date_utc is not null
|
||||
),
|
||||
booked_days_per_deal as (
|
||||
select
|
||||
|
|
@ -34,37 +34,37 @@ with
|
|||
) as previous_booked_date
|
||||
from int_core__bookings icb
|
||||
inner join int_core__user_host icuh on icb.id_user_host = icuh.id_user_host
|
||||
-- Ensure only Platform deals are considered (exclude API deals)
|
||||
inner join
|
||||
int_kpis__dimension_deals ikdd
|
||||
on icuh.id_deal = ikdd.id_deal
|
||||
and ikdd.client_type = 'PLATFORM'
|
||||
where icuh.id_deal is not null
|
||||
group by icuh.id_deal, icb.created_date_utc
|
||||
),
|
||||
deals as (
|
||||
select
|
||||
coalesce(hd.id_deal, h.id_deal) as id_deal,
|
||||
min(coalesce(hd.live_date_utc, h.created_date_utc)) as created_date_utc
|
||||
from int_hubspot__deal hd
|
||||
full outer join
|
||||
int_core__user_host h
|
||||
on hd.id_deal = h.id_deal
|
||||
where hd.id_deal is not null
|
||||
and h.id_deal is not null
|
||||
group by 1
|
||||
ikdd.id_deal,
|
||||
ikdd.client_type,
|
||||
ikdd.effective_deal_start_date_utc as created_date_utc
|
||||
from int_kpis__dimension_deals ikdd
|
||||
),
|
||||
deal_historic_booking_dates as (
|
||||
select
|
||||
d.date,
|
||||
h.id_deal,
|
||||
min(h.created_date_utc) as creation_date_utc,
|
||||
ikdd.id_deal,
|
||||
min(ikdd.client_type) as client_type,
|
||||
min(ikdd.created_date_utc) as creation_date_utc,
|
||||
min(b.created_date_utc) as first_time_booked_date_utc,
|
||||
max(b.created_date_utc) as last_time_booked_date_utc,
|
||||
max(b.previous_booked_date) as second_to_last_time_booked_date_utc
|
||||
from int_kpis__dimension_dates d
|
||||
inner join deals h on d.date >= h.created_date_utc
|
||||
inner join deals ikdd on d.date >= ikdd.created_date_utc
|
||||
left join
|
||||
booked_days_per_deal b
|
||||
on h.id_deal = b.id_deal
|
||||
on ikdd.id_deal = b.id_deal
|
||||
and d.date >= b.created_date_utc
|
||||
where h.id_deal is not null
|
||||
group by d.date, h.id_deal
|
||||
group by d.date, ikdd.id_deal
|
||||
),
|
||||
deal_historic_features as (
|
||||
select
|
||||
|
|
@ -75,6 +75,7 @@ with
|
|||
hhbf.last_time_booked_date_utc,
|
||||
hhbf.second_to_last_time_booked_date_utc,
|
||||
hdo.cancellation_date_utc,
|
||||
case when hhbf.client_type = 'API' then true else false end as is_api_deal,
|
||||
case
|
||||
when hhbf.date >= hdo.cancellation_date_utc then true else false
|
||||
end as deal_has_been_offboarded,
|
||||
|
|
@ -158,40 +159,56 @@ select
|
|||
-- Additionally, the deal has not been offboarded in hubspot.
|
||||
when deal_was_created_this_month and not deal_has_been_offboarded
|
||||
then '01-New'
|
||||
-- 02-Never Booked: The deal has been created before this month and has not
|
||||
-- had any booking. Additionally, the deal has not been offboarded in hubspot.
|
||||
-- 02-Never Booked: The deal is not API, has been created before this month
|
||||
-- and has not had any booking. Additionally, the deal has not been offboarded
|
||||
-- in hubspot.
|
||||
when
|
||||
not deal_has_at_least_one_booking
|
||||
and not deal_was_created_this_month
|
||||
and not deal_has_been_offboarded
|
||||
and not is_api_deal
|
||||
then '02-Never Booked'
|
||||
-- 04-Active: The deal has had at least 1 booking in its history and it's
|
||||
-- 04-Active:
|
||||
-- The deal is API, is not New and has not been offboarded
|
||||
-- The deal is not API and has had at least 1 booking in its history and it's
|
||||
-- been less than 12 months since the last booking and has not been offboarded
|
||||
-- in hubspot and is not reactivated and is not FTB
|
||||
when
|
||||
deal_has_at_least_one_booking
|
||||
-- API deals --
|
||||
is_api_deal
|
||||
and not deal_was_created_this_month
|
||||
and has_been_booked_within_last_12_months
|
||||
and not deal_has_been_offboarded
|
||||
-- not reactivated
|
||||
and not (
|
||||
had_previous_booking_more_than_12_months_before_the_last
|
||||
and has_been_booked_within_current_month
|
||||
-- Platform deals --
|
||||
or (
|
||||
not is_api_deal
|
||||
and deal_has_at_least_one_booking
|
||||
and not deal_was_created_this_month
|
||||
and has_been_booked_within_last_12_months
|
||||
and not deal_has_been_offboarded
|
||||
-- not reactivated
|
||||
and not (
|
||||
had_previous_booking_more_than_12_months_before_the_last
|
||||
and has_been_booked_within_current_month
|
||||
)
|
||||
)
|
||||
then '04-Active'
|
||||
-- 05-Churning: The deal has been offboarded this month. Alternatively, The
|
||||
-- deal has been booked at least once and it's been 12 months since the last
|
||||
-- 05-Churning: The deal has been offboarded this month.
|
||||
-- Alternatively, The
|
||||
-- deal has been booked at least once and it's been 12 months since
|
||||
-- the last
|
||||
-- booking
|
||||
when
|
||||
(
|
||||
deal_has_at_least_one_booking
|
||||
and last_booking_was_12_months_ago
|
||||
and not deal_has_been_offboarded
|
||||
and not is_api_deal
|
||||
)
|
||||
or deal_was_offboarded_this_month
|
||||
then '05-Churning'
|
||||
-- 06-Inactive: The deal has been offboarded in the past but not this month.
|
||||
-- Alternatively, the deal is not offboarded and the deal has been booked at
|
||||
-- 06-Inactive: The deal has been offboarded in the past but not this
|
||||
-- month.
|
||||
-- Alternatively, the deal is not offboarded and the deal has been
|
||||
-- booked at
|
||||
-- least once and it's been more than 12 months since the last booking.
|
||||
when
|
||||
(
|
||||
|
|
@ -199,15 +216,18 @@ select
|
|||
and not has_been_booked_within_last_12_months
|
||||
and not last_booking_was_12_months_ago
|
||||
and not deal_has_been_offboarded
|
||||
and not is_api_deal
|
||||
)
|
||||
or (deal_has_been_offboarded and not deal_was_offboarded_this_month)
|
||||
then '06-Inactive'
|
||||
-- 07-Reactivated: The deal is not offboarded but was churned/inactive, and
|
||||
-- 07-Reactivated: The deal is not offboarded but was
|
||||
-- churned/inactive, and
|
||||
-- now has had a new booking this month
|
||||
when
|
||||
had_previous_booking_more_than_12_months_before_the_last
|
||||
and has_been_booked_within_current_month
|
||||
and not deal_has_been_offboarded
|
||||
and not is_api_deal
|
||||
then '07-Reactivated'
|
||||
else null
|
||||
end as deal_lifecycle_state,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue