Merged PR 3247: Enriches monthly_growth_by_deal model for top losers reporting
# Description Changes: * Explicit selection of fields in the last part of the query, rather than select *. * Adding a few more Hubspot attributes, namely: AM, Hubspot Stage, Live Date and Cancellation Date. The main idea is to enrich the reporting with these. * Adding the listings over 12 months. Here it's a bit more tricky than for Revenue or Bookings, since to me the main indicator is the amount of listings that are being booked in a month, over a period of 12 months (rather than unique count of listings that have been booked in the past 12 months). However, doing a sum of the listings booked in month will be very tricky for AMs and other users. I opted for averaging, and can be considered as, in average, a certain account has X amount of listings with bookings created, and this average considers the past 12 months. So I'd say it's a good estimate of the "real" size of a client in terms of potential for Superhog. # Checklist - [X] The edited models and dependants run properly with production data. - [X] The edited models are sufficiently documented. - [X] The edited models contain PK tests, and I've ran and passed them. - [NA] I have checked for DRY opportunities with other models and docs. - [NA] I've picked the right materialization for the affected models. # Other - [ ] Check if a full-refresh is required after this PR is merged. Related work items: #22883
This commit is contained in:
parent
5735251c67
commit
f230eb3af5
4 changed files with 279 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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: |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue