change in new deals

This commit is contained in:
Joaquin 2025-03-13 17:19:34 +01:00
parent 1ced79ca0a
commit d6426b0066
3 changed files with 46 additions and 14 deletions

View file

@ -46,6 +46,7 @@ with
select
ikdd.id_deal,
ikdd.client_type,
ikdd.is_deal_in_hubspot,
ikdd.effective_deal_start_date_utc as created_date_utc
from int_kpis__dimension_deals ikdd
),
@ -53,6 +54,7 @@ with
select
d.date,
ikdd.id_deal,
ikdd.is_deal_in_hubspot,
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,
@ -64,12 +66,13 @@ with
booked_days_per_deal b
on ikdd.id_deal = b.id_deal
and d.date >= b.created_date_utc
group by d.date, ikdd.id_deal
group by d.date, ikdd.id_deal, ikdd.is_deal_in_hubspot
),
deal_historic_features as (
select
hhbf.date,
hhbf.id_deal,
hhbf.is_deal_in_hubspot,
hhbf.creation_date_utc,
hhbf.first_time_booked_date_utc,
hhbf.last_time_booked_date_utc,
@ -155,16 +158,23 @@ select
second_to_last_time_booked_date_utc,
cancellation_date_utc,
case
-- 01-New: The deal has been created this month.
-- 01-New: The deal has been created this month according to the data in
-- hubspot.
-- Additionally, the deal has not been offboarded in hubspot.
when deal_was_created_this_month and not deal_has_been_offboarded
when
deal_was_created_this_month
and not deal_has_been_offboarded
and is_deal_in_hubspot
then '01-New'
-- 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.
-- 02-Never Booked: The deal is not API, has been created before this month, or
-- it doesn't exist in hubspot, 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_was_created_this_month
or (deal_was_created_this_month and not is_deal_in_hubspot)
)
and not deal_has_been_offboarded
and not is_api_deal
then '02-Never Booked'
@ -174,14 +184,22 @@ select
-- been less than 12 months since the last booking and has not been offboarded
when
-- API deals --
is_api_deal
and not deal_was_created_this_month
and not deal_has_been_offboarded
(
is_api_deal
and (
not deal_was_created_this_month
or (deal_was_created_this_month and not is_deal_in_hubspot)
)
and not deal_has_been_offboarded
)
-- Platform deals --
or (
not is_api_deal
and deal_has_at_least_one_booking
and not deal_was_created_this_month
and (
not deal_was_created_this_month
or (deal_was_created_this_month and not is_deal_in_hubspot)
)
and has_been_booked_within_last_12_months
and not deal_has_been_offboarded
-- not reactivated