diff --git a/models/intermediate/cross/int_monthly_growth_score_by_deal.sql b/models/intermediate/cross/int_monthly_growth_score_by_deal.sql index 7312d2a..9047f6a 100644 --- a/models/intermediate/cross/int_monthly_growth_score_by_deal.sql +++ b/models/intermediate/cross/int_monthly_growth_score_by_deal.sql @@ -3,6 +3,7 @@ with int_monthly_aggregated_metrics_history_by_deal as ( select * from {{ ref("int_monthly_aggregated_metrics_history_by_deal") }} ), + int_hubspot__deal as (select * from {{ ref("int_hubspot__deal") }}), deal_history_from_previous_months as ( select year, @@ -30,6 +31,10 @@ with sum(deal_created_bookings_12_months_window) over ( partition by first_day_month ) as global_created_bookings_12_months_window, + deal_avg_listings_booked_in_month_12_months_window, + sum(deal_avg_listings_booked_in_month_12_months_window) over ( + partition by first_day_month + ) as global_avg_listings_booked_in_month_12_months_window, deal_revenue_12_months_window, effective_deal_revenue_12_months_window, sum(effective_deal_revenue_12_months_window) over ( @@ -39,6 +44,10 @@ with partition by first_day_month order by deal_created_bookings_12_months_window desc ) as deal_contribution_rank_to_global_created_bookings, + row_number() over ( + partition by first_day_month + order by deal_avg_listings_booked_in_month_12_months_window desc + ) as deal_contribution_rank_to_global_avg_listings_booked_in_month, row_number() over ( partition by first_day_month order by deal_revenue_12_months_window desc ) as deal_contribution_rank_to_global_revenue @@ -52,6 +61,9 @@ with coalesce( sum(previous_twelve_months.created_bookings), 0 ) as deal_created_bookings_12_months_window, + coalesce( + avg(previous_twelve_months.listings_booked_in_month), 0 + ) as deal_avg_listings_booked_in_month_12_months_window, coalesce( sum(previous_twelve_months.revenue_in_gbp), 0 ) as deal_revenue_12_months_window, @@ -141,6 +153,7 @@ with - 1 as yoy_listings_booked_in_month_growth, -- 12 Months Window (Account Size) -- + -- Bookings -- aggregated_12m_window.deal_created_bookings_12_months_window, aggregated_12m_window.global_created_bookings_12_months_window, coalesce( @@ -153,6 +166,29 @@ with 0 ) as deal_contribution_share_to_global_created_bookings, aggregated_12m_window.deal_contribution_rank_to_global_created_bookings, + + -- Listings -- + round( + aggregated_12m_window.deal_avg_listings_booked_in_month_12_months_window, + 2 + ) as deal_avg_listings_booked_in_month_12_months_window, + round( + aggregated_12m_window.global_avg_listings_booked_in_month_12_months_window, + 2 + ) as global_avg_listings_booked_in_month_12_months_window, + coalesce( + cast( + aggregated_12m_window.deal_avg_listings_booked_in_month_12_months_window + as decimal + ) / nullif( + aggregated_12m_window.global_avg_listings_booked_in_month_12_months_window, + 0 + ), + 0 + ) as deal_contribution_share_to_global_avg_listings_booked_in_month, + aggregated_12m_window.deal_contribution_rank_to_global_avg_listings_booked_in_month, + + -- Revenue -- aggregated_12m_window.deal_revenue_12_months_window, aggregated_12m_window.effective_deal_revenue_12_months_window, aggregated_12m_window.effective_global_revenue_12_months_window, @@ -243,6 +279,12 @@ with m.global_created_bookings_12_months_window, m.deal_contribution_share_to_global_created_bookings, m.deal_contribution_rank_to_global_created_bookings, + + m.deal_avg_listings_booked_in_month_12_months_window, + m.global_avg_listings_booked_in_month_12_months_window, + m.deal_contribution_share_to_global_avg_listings_booked_in_month, + m.deal_contribution_rank_to_global_avg_listings_booked_in_month, + m.deal_revenue_12_months_window, m.effective_deal_revenue_12_months_window, m.effective_global_revenue_12_months_window, @@ -300,20 +342,81 @@ with from metrics_attribution_to_given_month_per_deal m ) select - *, + gsc.date, + gsc.id_deal, + + gsc.main_deal_name, + gsc.main_billing_country_iso_3_per_deal, + gsc.deal_lifecycle_state, + d.deal_hubspot_stage, + d.account_manager, + d.live_date_utc, + d.cancellation_date_utc, + + gsc.given_month_first_day_month, + gsc.previous_1_month_first_day_month, + gsc.previous_2_month_first_day_month, + gsc.previous_12_month_first_day_month, + gsc.previous_13_month_first_day_month, + gsc.aggregated_revenue_from_first_day_month, + gsc.aggregated_revenue_to_first_day_month, + + gsc.given_month_revenue_in_gbp, + gsc.previous_1_month_revenue_in_gbp, + gsc.previous_2_month_revenue_in_gbp, + gsc.previous_12_month_revenue_in_gbp, + gsc.previous_13_month_revenue_in_gbp, + gsc.mom_revenue_growth, + gsc.mom_1_month_shift_revenue_growth, + gsc.yoy_revenue_growth, + gsc.yoy_1_month_shift_revenue_growth, + + gsc.given_month_created_bookings, + gsc.previous_1_month_created_bookings, + gsc.previous_12_month_created_bookings, + gsc.mom_created_bookings_growth, + gsc.yoy_created_bookings_growth, + + gsc.given_month_listings_booked_in_month, + gsc.previous_1_month_listings_booked_in_month, + gsc.previous_12_month_listings_booked_in_month, + gsc.mom_listings_booked_in_month_growth, + gsc.yoy_listings_booked_in_month_growth, + + gsc.deal_created_bookings_12_months_window, + gsc.global_created_bookings_12_months_window, + gsc.deal_contribution_share_to_global_created_bookings, + gsc.deal_contribution_rank_to_global_created_bookings, + + gsc.deal_avg_listings_booked_in_month_12_months_window, + gsc.global_avg_listings_booked_in_month_12_months_window, + gsc.deal_contribution_share_to_global_avg_listings_booked_in_month, + gsc.deal_contribution_rank_to_global_avg_listings_booked_in_month, + + gsc.deal_revenue_12_months_window, + gsc.effective_deal_revenue_12_months_window, + gsc.effective_global_revenue_12_months_window, + gsc.deal_contribution_share_to_global_revenue, + gsc.deal_contribution_rank_to_global_revenue, + gsc.avg_mom_growth_score, + gsc.avg_yoy_growth_score, + gsc.avg_growth_score, + gsc.weighted_avg_growth_score, + -- Applies a categorisation based on the score value. These scores thresholds are -- opinionated case - when weighted_avg_growth_score <= -1.0 + when gsc.weighted_avg_growth_score <= -1.0 then 'TOP LOSER' - when weighted_avg_growth_score > -1.0 and weighted_avg_growth_score < 0 + when gsc.weighted_avg_growth_score > -1.0 and gsc.weighted_avg_growth_score < 0 then 'LOSER' - when weighted_avg_growth_score = 0 + when gsc.weighted_avg_growth_score = 0 then 'FLAT' - when weighted_avg_growth_score > 0 and weighted_avg_growth_score < 1.0 + when gsc.weighted_avg_growth_score > 0 and gsc.weighted_avg_growth_score < 1.0 then 'WINNER' - when weighted_avg_growth_score >= 1.0 + when gsc.weighted_avg_growth_score >= 1.0 then 'TOP WINNER' else 'UNSET' end as categorisation_weighted_avg_growth_score -from growth_score_computation +from growth_score_computation gsc +left join int_hubspot__deal d on gsc.id_deal = d.id_deal diff --git a/models/intermediate/cross/schema.yml b/models/intermediate/cross/schema.yml index 989f382..9c49c4e 100644 --- a/models/intermediate/cross/schema.yml +++ b/models/intermediate/cross/schema.yml @@ -670,6 +670,28 @@ models: Identifier of the lifecycle state of a given deal in a given month. + - name: deal_hubspot_stage + data_type: string + description: | + Current hubspot stage for a given deal. + + - name: account_manager + data_type: string + description: | + Current Account Manager in charge of a given deal, according + to Hubspot. + + - name: live_date_utc + data_type: date + description: | + Date in which the account has gone live, according to Hubspot. + + - name: cancellation_date_utc + data_type: date + description: | + Date in which the account has been offboarded, according to + Hubspot. + - name: given_month_first_day_month data_type: date description: | @@ -1061,7 +1083,7 @@ models: - name: global_created_bookings_12_months_window data_type: integer description: | - Total created bookings generated by a deal + Total created bookings generated by any deal in the months from the period ranging from the aggregated_revenue_from_first_day_month to aggregated_revenue_to_first_day_month. @@ -1097,6 +1119,61 @@ models: tests: - not_null + - name: deal_avg_listings_booked_in_month_12_months_window + data_type: decimal + description: | + Average listings booked in month by a deal + in the months from the period ranging from the + aggregated_revenue_from_first_day_month to + aggregated_revenue_to_first_day_month. + It cannot be null. + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: false + + - name: global_avg_listings_booked_in_month_12_months_window + data_type: decimal + description: | + Sum of the average listings booked in month by + any deal in the months from the period ranging from the + aggregated_revenue_from_first_day_month to + aggregated_revenue_to_first_day_month. + It is used for the deal contribution share with respect + to the global average listings booked in month. + It cannot be null. + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: false + + - name: deal_contribution_share_to_global_avg_listings_booked_in_month + data_type: decimal + description: | + Represents the size of the deal in terms of average listings + booked in month. + In other words, what's the percentage of the global average listings + booked in month that can be attributed to this deal. + It cannot be null. + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: false + + - name: deal_contribution_rank_to_global_avg_listings_booked_in_month + data_type: decimal + description: | + Represents the ordered list of deals by descending size + in terms of average listings booked in month. + If more than one deal have the same share, the order is + not under control. + It cannot be null. + tests: + - not_null + - name: avg_mom_growth_score data_type: decimal description: | diff --git a/models/reporting/general/monthly_growth_score_by_deal.sql b/models/reporting/general/monthly_growth_score_by_deal.sql index 9c2263c..de91ce8 100644 --- a/models/reporting/general/monthly_growth_score_by_deal.sql +++ b/models/reporting/general/monthly_growth_score_by_deal.sql @@ -9,6 +9,10 @@ select main_deal_name as main_deal_name, main_billing_country_iso_3_per_deal as main_billing_country_iso_3_per_deal, deal_lifecycle_state as deal_lifecycle_state, + deal_hubspot_stage as deal_hubspot_stage, + account_manager as account_manager, + live_date_utc as live_date_utc, + cancellation_date_utc as cancellation_date_utc, given_month_first_day_month as given_month_first_day_month, previous_1_month_first_day_month as previous_1_month_first_day_month, @@ -50,6 +54,15 @@ select deal_contribution_rank_to_global_created_bookings as deal_contribution_rank_to_global_created_bookings, + deal_avg_listings_booked_in_month_12_months_window + as deal_avg_listings_booked_in_month_12_months_window, + global_avg_listings_booked_in_month_12_months_window + as global_avg_listings_booked_in_month_12_months_window, + deal_contribution_share_to_global_avg_listings_booked_in_month + as deal_contribution_share_to_global_avg_listings_booked_in_month, + deal_contribution_rank_to_global_avg_listings_booked_in_month + as deal_contribution_rank_to_global_avg_listings_booked_in_month, + deal_revenue_12_months_window as deal_revenue_12_months_window, effective_deal_revenue_12_months_window as effective_deal_revenue_12_months_window, effective_global_revenue_12_months_window diff --git a/models/reporting/general/schema.yml b/models/reporting/general/schema.yml index f7d62f6..6338a0f 100644 --- a/models/reporting/general/schema.yml +++ b/models/reporting/general/schema.yml @@ -595,6 +595,28 @@ models: Identifier of the lifecycle state of a given deal in a given month. + - name: deal_hubspot_stage + data_type: string + description: | + Current hubspot stage for a given deal. + + - name: account_manager + data_type: string + description: | + Current Account Manager in charge of a given deal, according + to Hubspot. + + - name: live_date_utc + data_type: date + description: | + Date in which the account has gone live, according to Hubspot. + + - name: cancellation_date_utc + data_type: date + description: | + Date in which the account has been offboarded, according to + Hubspot. + - name: given_month_first_day_month data_type: date description: | @@ -986,7 +1008,7 @@ models: - name: global_created_bookings_12_months_window data_type: integer description: | - Total created bookings generated by a deal + Total created bookings generated by any deal in the months from the period ranging from the aggregated_revenue_from_first_day_month to aggregated_revenue_to_first_day_month. @@ -1022,6 +1044,61 @@ models: tests: - not_null + - name: deal_avg_listings_booked_in_month_12_months_window + data_type: decimal + description: | + Average listings booked in month by a deal + in the months from the period ranging from the + aggregated_revenue_from_first_day_month to + aggregated_revenue_to_first_day_month. + It cannot be null. + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: false + + - name: global_avg_listings_booked_in_month_12_months_window + data_type: decimal + description: | + Sum of the average listings booked in month by + any deal in the months from the period ranging from the + aggregated_revenue_from_first_day_month to + aggregated_revenue_to_first_day_month. + It is used for the deal contribution share with respect + to the global average listings booked in month. + It cannot be null. + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: false + + - name: deal_contribution_share_to_global_avg_listings_booked_in_month + data_type: decimal + description: | + Represents the size of the deal in terms of average listings + booked in month. + In other words, what's the percentage of the global average listings + booked in month that can be attributed to this deal. + It cannot be null. + tests: + - not_null + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: false + + - name: deal_contribution_rank_to_global_avg_listings_booked_in_month + data_type: decimal + description: | + Represents the ordered list of deals by descending size + in terms of average listings booked in month. + If more than one deal have the same share, the order is + not under control. + It cannot be null. + tests: + - not_null + - name: avg_mom_growth_score data_type: decimal description: |