From 525720ea0ae15709acc48bc0975e66000a2fe495 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Fri, 14 Mar 2025 10:39:01 +0100 Subject: [PATCH] Changes in deals lifecycle --- .../kpis/int_kpis__lifecycle_daily_deal.sql | 38 ++++++++----------- models/intermediate/kpis/schema.yml | 5 ++- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql b/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql index dbc669a..2f775d8 100644 --- a/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql +++ b/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql @@ -158,25 +158,22 @@ select second_to_last_time_booked_date_utc, cancellation_date_utc, case - -- 01-New: The deal has been created this month according to the data in - -- hubspot. + -- 01-New: The deal has been created this month. -- Additionally, the deal has not been offboarded in hubspot. 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, or - -- it doesn't exist in hubspot, 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 - or (deal_was_created_this_month and not is_deal_in_hubspot) - ) + and not deal_was_created_this_month and not deal_has_been_offboarded and not is_api_deal + and is_deal_in_hubspot then '02-Never Booked' -- 04-Active: -- The deal is API, is not New and has not been offboarded @@ -184,22 +181,15 @@ 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 - or (deal_was_created_this_month and not is_deal_in_hubspot) - ) - and not deal_has_been_offboarded - ) + is_api_deal + and not deal_was_created_this_month + and not deal_has_been_offboarded + and is_deal_in_hubspot -- Platform deals -- or ( not is_api_deal and deal_has_at_least_one_booking - and ( - not deal_was_created_this_month - or (deal_was_created_this_month and not is_deal_in_hubspot) - ) + and not deal_was_created_this_month and has_been_booked_within_last_12_months and not deal_has_been_offboarded -- not reactivated @@ -207,6 +197,7 @@ select had_previous_booking_more_than_12_months_before_the_last and has_been_booked_within_current_month ) + and is_deal_in_hubspot ) then '04-Active' -- 05-Churning: The deal has been offboarded this month. @@ -222,6 +213,7 @@ select and not is_api_deal ) or deal_was_offboarded_this_month + and is_deal_in_hubspot then '05-Churning' -- 06-Inactive: The deal has been offboarded in the past but not this -- month. @@ -237,6 +229,7 @@ select and not is_api_deal ) or (deal_has_been_offboarded and not deal_was_offboarded_this_month) + and is_deal_in_hubspot then '06-Inactive' -- 07-Reactivated: The deal is not offboarded but was -- churned/inactive, and @@ -246,8 +239,9 @@ select and has_been_booked_within_current_month and not deal_has_been_offboarded and not is_api_deal + and is_deal_in_hubspot then '07-Reactivated' - else null + else '99-Not in HubSpot' end as deal_lifecycle_state, has_been_booked_within_current_month, has_been_booked_within_last_6_months, diff --git a/models/intermediate/kpis/schema.yml b/models/intermediate/kpis/schema.yml index fc3fdaf..4dd931f 100644 --- a/models/intermediate/kpis/schema.yml +++ b/models/intermediate/kpis/schema.yml @@ -316,7 +316,7 @@ models: - 05-Churning: Either Deals that are offboarded in that month or Deals that are becoming inactive because of lack of bookings in the past 12 months - 06-Inactive: Either Deals that have been previously offboarded or Deals that have not had a booking for more than 12 months. - 07-Reactivated: Deals that have had a booking in the current month that were inactive or churning before, that are not offboarded. - - Finally, if none of the logic applies, which should not happen, null will be set and a dbt alert will raise. + - 99-Not in HubSpot: Deals that are not in HubSpot so we can't determine the lifecycle state. Since the states of Active, First Time Booked and Reactivated indicate certain booking activity and are mutually exclusive, the model also provides information of the recency of the bookings by the following @@ -388,7 +388,7 @@ models: description: | Contains the lifecycle state of a deal. The accepted values are: 01-New, 02-Never Booked, 04-Active, 05-Churning, 06-Inactive, - 07-Reactivated. Failing to implement the logic will result in alert. + 07-Reactivated, 99-Not in Husbpot. data_tests: - not_null - accepted_values: @@ -399,6 +399,7 @@ models: - 05-Churning - 06-Inactive - 07-Reactivated + - 99-Not in HubSpot - name: has_been_booked_within_current_month data_type: boolean