From f8362c4a71e0dd5eb570f0d52fb5a2b719bb40e3 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 7 Mar 2025 11:32:09 +0100 Subject: [PATCH] addressed comments --- ...ted_metrics_history_by_deal_by_time_window.sql | 13 ++++++++++--- models/intermediate/cross/schema.yml | 15 ++++++++++++--- ...ted_metrics_history_by_deal_by_time_window.sql | 3 ++- models/reporting/general/schema.yml | 15 ++++++++++++--- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/models/intermediate/cross/int_monthly_aggregated_metrics_history_by_deal_by_time_window.sql b/models/intermediate/cross/int_monthly_aggregated_metrics_history_by_deal_by_time_window.sql index d65c5ca..0b5762e 100644 --- a/models/intermediate/cross/int_monthly_aggregated_metrics_history_by_deal_by_time_window.sql +++ b/models/intermediate/cross/int_monthly_aggregated_metrics_history_by_deal_by_time_window.sql @@ -593,13 +593,20 @@ select end as days_between_last_contacted_and_churn, d.amount_times_contacted, d.cancellation_category, + case + when mabd.deal_lifecycle_state = '{{churned_state}}' then true else false + end as is_churning, case when mabd.deal_lifecycle_state = '{{churned_state}}' and d.cancellation_date_utc is null - then true - else false - end as is_churning_from_inactivity, + then 'INACTIVITY' + when + mabd.deal_lifecycle_state = '{{churned_state}}' + and d.cancellation_date_utc is not null + then 'ACCOUNT CANCELLATION' + else null + end as churn_reason, -- Windowed metrics coalesce(mabd.sum_created_bookings, 0) as created_bookings, diff --git a/models/intermediate/cross/schema.yml b/models/intermediate/cross/schema.yml index a91cfc2..34185c0 100644 --- a/models/intermediate/cross/schema.yml +++ b/models/intermediate/cross/schema.yml @@ -1668,11 +1668,20 @@ models: Number of times the deal was contacted according to Hubspot. - - name: is_churning_from_inactivity + - name: is_churning data_type: boolean description: | - Flag to identify if the deal is churning due to - inactivity because of lack of bookings in the past 12 months. + Flag to identify if the deal is churning or not. + + - name: churn_reason + data_type: string + description: | + Reason why the deal is churning. + data_tests: + - accepted_values: + values: + - "INACTIVITY" + - "ACCOUNT CANCELLATION" - name: created_bookings data_type: integer diff --git a/models/reporting/general/monthly_aggregated_metrics_history_by_deal_by_time_window.sql b/models/reporting/general/monthly_aggregated_metrics_history_by_deal_by_time_window.sql index 8c5721a..d624010 100644 --- a/models/reporting/general/monthly_aggregated_metrics_history_by_deal_by_time_window.sql +++ b/models/reporting/general/monthly_aggregated_metrics_history_by_deal_by_time_window.sql @@ -28,7 +28,8 @@ select days_between_last_contacted_and_churn as days_between_last_contacted_and_churn, amount_times_contacted as amount_times_contacted, cancellation_category as cancellation_category, - is_churning_from_inactivity as is_churning_from_inactivity, + is_churning as is_churning, + churn_reason as churn_reason, created_bookings as created_bookings, listings_booked_in_month as listings_booked_in_month, total_revenue_in_gbp as total_revenue_in_gbp, diff --git a/models/reporting/general/schema.yml b/models/reporting/general/schema.yml index 81f270d..2870cad 100644 --- a/models/reporting/general/schema.yml +++ b/models/reporting/general/schema.yml @@ -1644,11 +1644,20 @@ models: Number of times the deal was contacted according to Hubspot. - - name: is_churning_from_inactivity + - name: is_churning data_type: boolean description: | - Flag to identify if the deal is churning due to - inactivity because of lack of bookings in the past 12 months. + Flag to identify if the deal is churning or not. + + - name: churn_reason + data_type: string + description: | + Reason why the deal is churning. + data_tests: + - accepted_values: + values: + - "INACTIVITY" + - "ACCOUNT CANCELLATION" - name: created_bookings data_type: integer