Changes in deals lifecycle

This commit is contained in:
Joaquin 2025-03-14 10:39:01 +01:00
parent e827c0f9d5
commit 525720ea0a
2 changed files with 19 additions and 24 deletions

View file

@ -158,25 +158,22 @@ select
second_to_last_time_booked_date_utc, second_to_last_time_booked_date_utc,
cancellation_date_utc, cancellation_date_utc,
case case
-- 01-New: The deal has been created this month according to the data in -- 01-New: The deal has been created this month.
-- hubspot.
-- Additionally, the deal has not been offboarded in hubspot. -- Additionally, the deal has not been offboarded in hubspot.
when when
deal_was_created_this_month deal_was_created_this_month
and not deal_has_been_offboarded and not deal_has_been_offboarded
and is_deal_in_hubspot and is_deal_in_hubspot
then '01-New' then '01-New'
-- 02-Never Booked: The deal is not API, has been created before this month, or -- 02-Never Booked: The deal is not API, has been created before this month
-- it doesn't exist in hubspot, and has not had any booking. -- and has not had any booking. Additionally, the deal has not been offboarded
-- Additionally, the deal has not been offboarded in hubspot. -- in hubspot.
when when
not deal_has_at_least_one_booking not deal_has_at_least_one_booking
and ( and not deal_was_created_this_month
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 deal_has_been_offboarded
and not is_api_deal and not is_api_deal
and is_deal_in_hubspot
then '02-Never Booked' then '02-Never Booked'
-- 04-Active: -- 04-Active:
-- The deal is API, is not New and has not been offboarded -- 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 -- been less than 12 months since the last booking and has not been offboarded
when when
-- API deals -- -- API deals --
( is_api_deal
is_api_deal and not deal_was_created_this_month
and ( and not deal_has_been_offboarded
not deal_was_created_this_month and is_deal_in_hubspot
or (deal_was_created_this_month and not is_deal_in_hubspot)
)
and not deal_has_been_offboarded
)
-- Platform deals -- -- Platform deals --
or ( or (
not is_api_deal not is_api_deal
and deal_has_at_least_one_booking and deal_has_at_least_one_booking
and ( and not deal_was_created_this_month
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 has_been_booked_within_last_12_months
and not deal_has_been_offboarded and not deal_has_been_offboarded
-- not reactivated -- not reactivated
@ -207,6 +197,7 @@ select
had_previous_booking_more_than_12_months_before_the_last had_previous_booking_more_than_12_months_before_the_last
and has_been_booked_within_current_month and has_been_booked_within_current_month
) )
and is_deal_in_hubspot
) )
then '04-Active' then '04-Active'
-- 05-Churning: The deal has been offboarded this month. -- 05-Churning: The deal has been offboarded this month.
@ -222,6 +213,7 @@ select
and not is_api_deal and not is_api_deal
) )
or deal_was_offboarded_this_month or deal_was_offboarded_this_month
and is_deal_in_hubspot
then '05-Churning' then '05-Churning'
-- 06-Inactive: The deal has been offboarded in the past but not this -- 06-Inactive: The deal has been offboarded in the past but not this
-- month. -- month.
@ -237,6 +229,7 @@ select
and not is_api_deal and not is_api_deal
) )
or (deal_has_been_offboarded and not deal_was_offboarded_this_month) or (deal_has_been_offboarded and not deal_was_offboarded_this_month)
and is_deal_in_hubspot
then '06-Inactive' then '06-Inactive'
-- 07-Reactivated: The deal is not offboarded but was -- 07-Reactivated: The deal is not offboarded but was
-- churned/inactive, and -- churned/inactive, and
@ -246,8 +239,9 @@ select
and has_been_booked_within_current_month and has_been_booked_within_current_month
and not deal_has_been_offboarded and not deal_has_been_offboarded
and not is_api_deal and not is_api_deal
and is_deal_in_hubspot
then '07-Reactivated' then '07-Reactivated'
else null else '99-Not in HubSpot'
end as deal_lifecycle_state, end as deal_lifecycle_state,
has_been_booked_within_current_month, has_been_booked_within_current_month,
has_been_booked_within_last_6_months, has_been_booked_within_last_6_months,

View file

@ -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 - 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. - 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. - 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 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 mutually exclusive, the model also provides information of the recency of the bookings by the following
@ -388,7 +388,7 @@ models:
description: | description: |
Contains the lifecycle state of a deal. The accepted values are: Contains the lifecycle state of a deal. The accepted values are:
01-New, 02-Never Booked, 04-Active, 05-Churning, 06-Inactive, 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: data_tests:
- not_null - not_null
- accepted_values: - accepted_values:
@ -399,6 +399,7 @@ models:
- 05-Churning - 05-Churning
- 06-Inactive - 06-Inactive
- 07-Reactivated - 07-Reactivated
- 99-Not in HubSpot
- name: has_been_booked_within_current_month - name: has_been_booked_within_current_month
data_type: boolean data_type: boolean