From 39de8617b73c5590665ec40ac77c77d2eec4706b Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Mon, 27 Jan 2025 18:26:19 +0100 Subject: [PATCH 1/9] New expected MRR metric --- .../cross/int_mtd_aggregated_metrics.sql | 9 +++++ .../int_mtd_vs_previous_year_metrics.sql | 34 +++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/models/intermediate/cross/int_mtd_aggregated_metrics.sql b/models/intermediate/cross/int_mtd_aggregated_metrics.sql index faae9a6..bff82ab 100644 --- a/models/intermediate/cross/int_mtd_aggregated_metrics.sql +++ b/models/intermediate/cross/int_mtd_aggregated_metrics.sql @@ -308,6 +308,15 @@ { "order_by": 203, "metric": "Expected Onboarding MRR per New Account", + "value": "expected_mrr_per_account", + "previous_year_value": "previous_year_expected_mrr_per_account", + "relative_increment": "relative_increment_expected_mrr_per_account", + "number_format": "currency_gbp", + "increment_sign_format": "positive", + }, + { + "order_by": 204, + "metric": "Expected Onboarding MRR", "value": "expected_mrr", "previous_year_value": "previous_year_expected_mrr", "relative_increment": "relative_increment_expected_mrr", diff --git a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql index 2e74aba..0be1afb 100644 --- a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql +++ b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql @@ -418,7 +418,11 @@ with }} as revenue_retained_post_resolutions_ratio, -- ONBOARDING MRR METRIC -- - onboarding_mrr.expected_mrr as expected_mrr + onboarding_mrr.expected_mrr as expected_mrr_per_account, + case + when d.dimension = 'by_number_of_listings' then + onboarding_mrr.expected_mrr * deals.new_deals else null + end as number_of_listings_expected_mrr from int_kpis__agg_dates_main_kpis d left join @@ -496,7 +500,30 @@ with on d.date = onboarding_mrr.date and d.dimension = onboarding_mrr.dimension and d.dimension_value = onboarding_mrr.dimension_value + ), + global_expected_mrr as ( + select + pkc.year, + pkc.month, + pkc.day, + 'global' as dimension, + sum(pkc.new_deals*pkc.expected_mrr_per_account) as global_expected_mrr + from plain_kpi_combination pkc + where + pkc.dimension = 'by_number_of_listings' + group by 1, 2, 3, 4 + ), + plain_kpi_combination_with_mrr as ( + select + pkc.*, + coalesce(gem.global_expected_mrr, pkc.number_of_listings_expected_mrr) as expected_mrr + from plain_kpi_combination pkc + left join global_expected_mrr gem on pkc.year = gem.year + and pkc.month = gem.month + and pkc.day = gem.day + and pkc.dimension = gem.dimension ) + select current.year, current.month, @@ -636,11 +663,12 @@ select {{ calculate_safe_relative_increment("revenue_retained_post_resolutions_ratio") }}, -- ONBOARDING MRR METRIC -- + {{ calculate_safe_relative_increment("expected_mrr_per_account") }}, {{ calculate_safe_relative_increment("expected_mrr") }} -from plain_kpi_combination current +from plain_kpi_combination_with_mrr current left join - plain_kpi_combination previous_year + plain_kpi_combination_with_mrr previous_year on current.dimension = previous_year.dimension and current.dimension_value = previous_year.dimension_value and current.month = previous_year.month From 8bd5851235bdf24882ff48eb6c45d3f91388e9c4 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Tue, 28 Jan 2025 12:26:53 +0100 Subject: [PATCH 2/9] created new model to get all mrr metrics --- .../int_mtd_agg_onboarding_mrr_metrics.sql | 70 +++++++++++++++++++ .../cross/int_mtd_aggregated_metrics.sql | 8 +-- .../int_mtd_vs_previous_year_metrics.sql | 65 +++-------------- 3 files changed, 82 insertions(+), 61 deletions(-) create mode 100644 models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql diff --git a/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql b/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql new file mode 100644 index 0000000..6d0aff5 --- /dev/null +++ b/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql @@ -0,0 +1,70 @@ +with + monthly_new_deals as ( + select + date_trunc('MONTH', effective_deal_start_date_utc)::date as start_month, + hubspot_listing_segmentation, + count(id_deal) as number_of_new_deals + from {{ ref("int_kpis__dimension_deals") }} + group by 1, 2 + ), + onboarding_mrr_metrics as ( + select + mom.date, + 'by_number_of_listings' as dimension, + mom.hubspot_listing_segmentation as dimension_value, + mnd.number_of_new_deals, + mom.expected_mrr as expected_mrr_per_deal, + mom.expected_mrr * mnd.number_of_new_deals as expected_mrr + from {{ ref("int_monthly_onboarding_mrr_metrics") }} mom + left join + monthly_new_deals mnd + on date_trunc('MONTH', mom.date)::date = mnd.start_month + and mom.hubspot_listing_segmentation = mnd.hubspot_listing_segmentation + where + mom.main_billing_country_iso_3 = 'global' + and mom.hubspot_listing_segmentation <> 'global' + union all + select + date, + 'by_billing_country' as dimension, + main_billing_country_iso_3 as dimension_value, + null as number_of_new_deals, + expected_mrr as expected_mrr_per_deal, + null as expected_mrr + from {{ ref("int_monthly_onboarding_mrr_metrics") }} + where + hubspot_listing_segmentation = 'global' + and main_billing_country_iso_3 <> 'global' + union all + select + date, + 'global' as dimension, + 'global' as dimension_value, + null as number_of_new_deals, + expected_mrr as expected_mrr_per_deal, + null as expected_mrr + from {{ ref("int_monthly_onboarding_mrr_metrics") }} + where + hubspot_listing_segmentation = 'global' + and main_billing_country_iso_3 = 'global' + ), + global_expected_mrr as ( + select + omm.date, + 'global' as dimension, + sum(omm.number_of_new_deals) as number_of_new_deals, + sum(omm.number_of_new_deals * omm.expected_mrr_per_deal) as expected_mrr + from onboarding_mrr_metrics omm + where omm.dimension = 'by_number_of_listings' + group by 1, 2 + ) +select + omm.date, + omm.dimension, + omm.dimension_value, + coalesce(gem.number_of_new_deals, omm.number_of_new_deals) as number_of_new_deals, + omm.expected_mrr_per_deal, + coalesce(gem.expected_mrr, omm.expected_mrr) as expected_mrr +from onboarding_mrr_metrics omm +left join + global_expected_mrr gem on omm.date = gem.date and omm.dimension = gem.dimension diff --git a/models/intermediate/cross/int_mtd_aggregated_metrics.sql b/models/intermediate/cross/int_mtd_aggregated_metrics.sql index bff82ab..c8d7f74 100644 --- a/models/intermediate/cross/int_mtd_aggregated_metrics.sql +++ b/models/intermediate/cross/int_mtd_aggregated_metrics.sql @@ -307,10 +307,10 @@ }, { "order_by": 203, - "metric": "Expected Onboarding MRR per New Account", - "value": "expected_mrr_per_account", - "previous_year_value": "previous_year_expected_mrr_per_account", - "relative_increment": "relative_increment_expected_mrr_per_account", + "metric": "Expected Onboarding MRR per New Deal", + "value": "expected_mrr_per_deal", + "previous_year_value": "previous_year_expected_mrr_per_deal", + "relative_increment": "relative_increment_expected_mrr_per_deal", "number_format": "currency_gbp", "increment_sign_format": "positive", }, diff --git a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql index 0be1afb..54640f4 100644 --- a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql +++ b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql @@ -171,32 +171,8 @@ with dimension in ('global', 'by_number_of_listings', 'by_billing_country') and dimension_value <> 'UNSET' ), - int_monthly_onboarding_mrr_metrics as ( - select - date, - 'by_number_of_listings' as dimension, - hubspot_listing_segmentation as dimension_value, - expected_mrr - from {{ ref("int_monthly_onboarding_mrr_metrics") }} - where - main_billing_country_iso_3 = 'global' - and hubspot_listing_segmentation <> 'global' - union all - select - date, - 'by_billing_country' as dimension, - main_billing_country_iso_3 as dimension_value, - expected_mrr - from {{ ref("int_monthly_onboarding_mrr_metrics") }} - where - hubspot_listing_segmentation = 'global' - and main_billing_country_iso_3 <> 'global' - union all - select date, 'global' as dimension, 'global' as dimension_value, expected_mrr - from {{ ref("int_monthly_onboarding_mrr_metrics") }} - where - hubspot_listing_segmentation = 'global' - and main_billing_country_iso_3 = 'global' + int_mtd_agg_onboarding_mrr_metrics as ( + select * from {{ ref("int_mtd_agg_onboarding_mrr_metrics") }} ), plain_kpi_combination as ( @@ -418,11 +394,8 @@ with }} as revenue_retained_post_resolutions_ratio, -- ONBOARDING MRR METRIC -- - onboarding_mrr.expected_mrr as expected_mrr_per_account, - case - when d.dimension = 'by_number_of_listings' then - onboarding_mrr.expected_mrr * deals.new_deals else null - end as number_of_listings_expected_mrr + onboarding_mrr.expected_mrr_per_deal, + onboarding_mrr.expected_mrr from int_kpis__agg_dates_main_kpis d left join @@ -496,32 +469,10 @@ with and d.dimension = churn.dimension and d.dimension_value = churn.dimension_value left join - int_monthly_onboarding_mrr_metrics onboarding_mrr + int_mtd_agg_onboarding_mrr_metrics onboarding_mrr on d.date = onboarding_mrr.date and d.dimension = onboarding_mrr.dimension and d.dimension_value = onboarding_mrr.dimension_value - ), - global_expected_mrr as ( - select - pkc.year, - pkc.month, - pkc.day, - 'global' as dimension, - sum(pkc.new_deals*pkc.expected_mrr_per_account) as global_expected_mrr - from plain_kpi_combination pkc - where - pkc.dimension = 'by_number_of_listings' - group by 1, 2, 3, 4 - ), - plain_kpi_combination_with_mrr as ( - select - pkc.*, - coalesce(gem.global_expected_mrr, pkc.number_of_listings_expected_mrr) as expected_mrr - from plain_kpi_combination pkc - left join global_expected_mrr gem on pkc.year = gem.year - and pkc.month = gem.month - and pkc.day = gem.day - and pkc.dimension = gem.dimension ) select @@ -663,12 +614,12 @@ select {{ calculate_safe_relative_increment("revenue_retained_post_resolutions_ratio") }}, -- ONBOARDING MRR METRIC -- - {{ calculate_safe_relative_increment("expected_mrr_per_account") }}, + {{ calculate_safe_relative_increment("expected_mrr_per_deal") }}, {{ calculate_safe_relative_increment("expected_mrr") }} -from plain_kpi_combination_with_mrr current +from plain_kpi_combination current left join - plain_kpi_combination_with_mrr previous_year + plain_kpi_combination previous_year on current.dimension = previous_year.dimension and current.dimension_value = previous_year.dimension_value and current.month = previous_year.month From 88e86ea9ed66cb8942b4edb80e2013f0ad2c805c Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Tue, 28 Jan 2025 12:41:03 +0100 Subject: [PATCH 3/9] Added schema --- models/intermediate/cross/schema.yml | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/models/intermediate/cross/schema.yml b/models/intermediate/cross/schema.yml index a19a116..71cac76 100644 --- a/models/intermediate/cross/schema.yml +++ b/models/intermediate/cross/schema.yml @@ -1779,3 +1779,54 @@ models: "Expected MRR for each new deal." data_tests: - not_null + + - name: int_mtd_agg_onboarding_mrr_metrics + description: | + This model contains the month-to-date aggregated metrics for the onboarding MRR. + It includes the expected MRR per deal and the total expected MRR, which is obtained + by summing the expected MRRs for all new deals. + + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - date + - dimension + - dimension_value + + columns: + - name: date + data_type: date + description: The date for the month-to-date metrics. + data_tests: + - not_null + + - name: dimension + data_type: string + description: The dimension or granularity of the metrics. + data_tests: + - accepted_values: + values: + - global + - by_number_of_listings + - by_billing_country + + - name: dimension_value + data_type: string + description: The value or segment available for the selected dimension. + data_tests: + - not_null + + - name: number_of_new_deals + data_type: numeric + description: Number of new deals in the month. + + - name: expected_mrr_per_deal + data_type: numeric + description: Expected Onboarding MRR per new deal. + + - name: expected_mrr + data_type: numeric + description: | + Total expected Onboarding MRR. + This is calculated by multiplying the expected MRR per deal by the number of new deals. + For the "global" dimension, it is the sum of all expected MRRs across segments. From cea7cdb34d051e5f1a3017f6b9f7baf7d96dfa78 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Tue, 28 Jan 2025 12:53:44 +0100 Subject: [PATCH 4/9] Removed first_time_booked_deals metric --- .../cross/int_mtd_aggregated_metrics.sql | 15 +++------------ .../cross/int_mtd_vs_previous_year_metrics.sql | 2 -- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/models/intermediate/cross/int_mtd_aggregated_metrics.sql b/models/intermediate/cross/int_mtd_aggregated_metrics.sql index c8d7f74..46f6958 100644 --- a/models/intermediate/cross/int_mtd_aggregated_metrics.sql +++ b/models/intermediate/cross/int_mtd_aggregated_metrics.sql @@ -82,15 +82,6 @@ }, { "order_by": 21, - "metric": "First Time Booked Deals", - "value": "first_time_booked_deals", - "previous_year_value": "previous_year_first_time_booked_deals", - "relative_increment": "relative_increment_first_time_booked_deals", - "number_format": "integer", - "increment_sign_format": "positive", - }, - { - "order_by": 22, "metric": "Deals Booked in Month", "value": "deals_booked_in_month", "previous_year_value": "previous_year_deals_booked_in_month", @@ -99,7 +90,7 @@ "increment_sign_format": "positive", }, { - "order_by": 23, + "order_by": 22, "metric": "Deals Booked in 6 Months", "value": "deals_booked_in_6_months", "previous_year_value": "previous_year_deals_booked_in_6_months", @@ -108,7 +99,7 @@ "increment_sign_format": "positive", }, { - "order_by": 24, + "order_by": 23, "metric": "Deals Booked in 12 Months", "value": "deals_booked_in_12_months", "previous_year_value": "previous_year_deals_booked_in_12_months", @@ -117,7 +108,7 @@ "increment_sign_format": "positive", }, { - "order_by": 25, + "order_by": 24, "metric": "Churning Deals", "value": "churning_deals", "previous_year_value": "previous_year_churning_deals", diff --git a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql index 54640f4..e74653a 100644 --- a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql +++ b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql @@ -217,7 +217,6 @@ with -- DEALS -- deals.new_deals, deals.never_booked_deals, - deals.first_time_booked_deals, deals.active_deals, deals.churning_deals, deals.inactive_deals, @@ -507,7 +506,6 @@ select -- DEALS -- {{ calculate_safe_relative_increment("new_deals") }}, {{ calculate_safe_relative_increment("never_booked_deals") }}, - {{ calculate_safe_relative_increment("first_time_booked_deals") }}, {{ calculate_safe_relative_increment("active_deals") }}, {{ calculate_safe_relative_increment("churning_deals") }}, {{ calculate_safe_relative_increment("inactive_deals") }}, From cf024f7b71ea750fad8d31937b96a857a1bc6762 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Tue, 28 Jan 2025 16:47:44 +0100 Subject: [PATCH 5/9] wip --- .../int_mtd_agg_onboarding_mrr_metrics.sql | 21 ++++++++----------- .../kpis/int_kpis__lifecycle_daily_deal.sql | 9 ++++---- .../kpis/int_kpis__metric_daily_deals.sql | 9 +++++--- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql b/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql index 6d0aff5..1f02314 100644 --- a/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql +++ b/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql @@ -1,25 +1,22 @@ with - monthly_new_deals as ( - select - date_trunc('MONTH', effective_deal_start_date_utc)::date as start_month, - hubspot_listing_segmentation, - count(id_deal) as number_of_new_deals - from {{ ref("int_kpis__dimension_deals") }} - group by 1, 2 + int_kpis__agg_daily_deals as ( + select date, dimension_value as hubspot_listing_segmentation, new_deals + from {{ ref("int_kpis__agg_daily_deals") }} + where dimension = 'by_number_of_listings' ), onboarding_mrr_metrics as ( select mom.date, 'by_number_of_listings' as dimension, mom.hubspot_listing_segmentation as dimension_value, - mnd.number_of_new_deals, + ad.number_of_new_deals, mom.expected_mrr as expected_mrr_per_deal, - mom.expected_mrr * mnd.number_of_new_deals as expected_mrr + mom.expected_mrr * ad.number_of_new_deals as expected_mrr from {{ ref("int_monthly_onboarding_mrr_metrics") }} mom left join - monthly_new_deals mnd - on date_trunc('MONTH', mom.date)::date = mnd.start_month - and mom.hubspot_listing_segmentation = mnd.hubspot_listing_segmentation + int_kpis__agg_daily_deals ad + on mom.date = ad.date + and mom.hubspot_listing_segmentation = ad.hubspot_listing_segmentation where mom.main_billing_country_iso_3 = 'global' and mom.hubspot_listing_segmentation <> 'global' diff --git a/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql b/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql index 70f700f..f621694 100644 --- a/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql +++ b/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql @@ -28,14 +28,15 @@ with booked_days_per_deal as ( select icuh.id_deal, - icb.created_date_utc, - lag(icb.created_date_utc, 1) over ( - partition by icuh.id_deal order by icb.created_date_utc asc + hd.live_date_utc as created_date_utc, + lag(hd.live_date_utc, 1) over ( + partition by icuh.id_deal order by hd.live_date_utc asc ) as previous_booked_date from int_core__bookings icb inner join int_core__user_host icuh on icb.id_user_host = icuh.id_user_host + inner join int_hubspot__deal hd on icuh.id_deal = hd.id_deal where icuh.id_deal is not null - group by icuh.id_deal, icb.created_date_utc + group by icuh.id_deal, hd.live_date_utc ), deal_historic_booking_dates as ( select diff --git a/models/intermediate/kpis/int_kpis__metric_daily_deals.sql b/models/intermediate/kpis/int_kpis__metric_daily_deals.sql index 6a93dbb..84a1e68 100644 --- a/models/intermediate/kpis/int_kpis__metric_daily_deals.sql +++ b/models/intermediate/kpis/int_kpis__metric_daily_deals.sql @@ -14,9 +14,11 @@ select coalesce( icd.main_billing_country_iso_3_per_deal, 'UNSET' ) as main_billing_country_iso_3_per_deal, - coalesce( - icmas.active_accommodations_per_deal_segmentation, 'UNSET' - ) as active_accommodations_per_deal_segmentation, + case + when ldl.deal_lifecycle_state = '01-New' + then coalesce(dd.hubspot_listing_segmentation, 'UNSET') + else coalesce(icmas.active_accommodations_per_deal_segmentation, 'UNSET') + end as active_accommodations_per_deal_segmentation, -- Metrics -- count( distinct case @@ -66,6 +68,7 @@ select ) as deals_booked_in_12_months from {{ ref("int_kpis__lifecycle_daily_deal") }} as ldl left join {{ ref("int_core__deal") }} as icd on ldl.id_deal = icd.id_deal +left join {{ ref("int_kpis__dimension_deals") }} as dd on ldl.id_deal = dd.id_deal left join {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas on ldl.id_deal = icmas.id_deal From 26898322e73cf3bb0ef3cef8e4441f9346af000c Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Wed, 29 Jan 2025 10:05:41 +0100 Subject: [PATCH 6/9] wip fixing deals from hubspot --- .../int_monthly_onboarding_mrr_metrics.sql | 63 ----------------- .../int_monthly_onboarding_mrr_per_deal.sql | 67 +++++++++++++++++++ .../int_mtd_agg_onboarding_mrr_metrics.sql | 67 ------------------- .../int_mtd_agg_onboarding_mrr_revenue.sql | 31 +++++++++ .../int_mtd_vs_previous_year_metrics.sql | 59 +++++++--------- models/intermediate/cross/schema.yml | 62 +++++------------ 6 files changed, 136 insertions(+), 213 deletions(-) delete mode 100644 models/intermediate/cross/int_monthly_onboarding_mrr_metrics.sql create mode 100644 models/intermediate/cross/int_monthly_onboarding_mrr_per_deal.sql delete mode 100644 models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql create mode 100644 models/intermediate/cross/int_mtd_agg_onboarding_mrr_revenue.sql diff --git a/models/intermediate/cross/int_monthly_onboarding_mrr_metrics.sql b/models/intermediate/cross/int_monthly_onboarding_mrr_metrics.sql deleted file mode 100644 index fbee173..0000000 --- a/models/intermediate/cross/int_monthly_onboarding_mrr_metrics.sql +++ /dev/null @@ -1,63 +0,0 @@ -with - deal_attributes as ( - select - id_deal, - coalesce( - main_billing_country_iso_3_per_deal, 'UNSET' - ) as main_billing_country_iso_3_per_deal, - effective_deal_start_month, - hubspot_deal_cancellation_month, - coalesce( - hubspot_listing_segmentation, 'UNSET' - ) as hubspot_listing_segmentation - from {{ ref("int_kpis__dimension_deals") }} - -- Exclude deals without live dates - where effective_deal_start_date_utc is not null - ), - monthly_revenue_per_number_of_properties as ( - select - m.date, - coalesce( - d.main_billing_country_iso_3_per_deal, 'global' - ) as main_billing_country_iso_3, - coalesce( - d.hubspot_listing_segmentation, 'global' - ) as hubspot_listing_segmentation, - count(*) as deals_active_in_month, - sum(coalesce(m.total_revenue_in_gbp, 0)) as total_revenue_in_gbp - from {{ ref("int_monthly_aggregated_metrics_history_by_deal") }} m - inner join - deal_attributes d - on m.id_deal = d.id_deal - and date_trunc('month', m.date) - >= date_trunc('month', d.effective_deal_start_month) - and date_trunc('month', m.date) - <= coalesce(d.hubspot_deal_cancellation_month, '2099-01-01') - and date_trunc('month', m.date)::date <> date_trunc('month', now())::date - where d.hubspot_listing_segmentation <> 'UNSET' - group by - cube ( - m.date, - d.hubspot_listing_segmentation, - d.main_billing_country_iso_3_per_deal - ) - -- Exclude total date aggregation - having m.date is not null - ) -select - r.date, - r.main_billing_country_iso_3, - r.hubspot_listing_segmentation, - sum(coalesce(m.total_revenue_in_gbp, 0)) as total_revenue_in_gbp, - sum(m.deals_active_in_month) as total_active_months, - sum(coalesce(m.total_revenue_in_gbp, 0)) - / sum(m.deals_active_in_month) as expected_mrr -from monthly_revenue_per_number_of_properties m -inner join - monthly_revenue_per_number_of_properties r - on r.date >= m.date - and r.date < m.date + interval '12 months' - and r.hubspot_listing_segmentation = m.hubspot_listing_segmentation - and r.main_billing_country_iso_3 = m.main_billing_country_iso_3 -where r.main_billing_country_iso_3 <> 'UNSET' -group by r.date, r.hubspot_listing_segmentation, r.main_billing_country_iso_3 diff --git a/models/intermediate/cross/int_monthly_onboarding_mrr_per_deal.sql b/models/intermediate/cross/int_monthly_onboarding_mrr_per_deal.sql new file mode 100644 index 0000000..9f5181c --- /dev/null +++ b/models/intermediate/cross/int_monthly_onboarding_mrr_per_deal.sql @@ -0,0 +1,67 @@ +with + int_monthly_aggregated_metrics_history_by_deal as ( + select * from {{ ref("int_monthly_aggregated_metrics_history_by_deal") }} + ), + deal_attributes as ( + select + id_deal, + coalesce( + main_billing_country_iso_3_per_deal, 'UNSET' + ) as main_billing_country_iso_3_per_deal, + effective_deal_start_month, + hubspot_deal_cancellation_month, + coalesce( + hubspot_listing_segmentation, 'UNSET' + ) as hubspot_listing_segmentation + from {{ ref("int_kpis__dimension_deals") }} + -- Exclude deals without live dates + where effective_deal_start_date_utc is not null + ) +-- Calculate expected MRR per deal by each dimension +select + m.date, + 'by_number_of_listings' as dimension, + d.hubspot_listing_segmentation as dimension_value, + sum(coalesce(m.total_revenue_in_gbp, 0)) / count(*) as expected_mrr_per_deal +from int_monthly_aggregated_metrics_history_by_deal m +inner join + deal_attributes d + on m.id_deal = d.id_deal + and date_trunc('month', m.date) >= date_trunc('month', d.effective_deal_start_month) + and date_trunc('month', m.date) + <= coalesce(d.hubspot_deal_cancellation_month, '2099-01-01') + and date_trunc('month', m.date)::date <> date_trunc('month', now())::date +where d.hubspot_listing_segmentation <> 'UNSET' +group by 1, 2, 3 +union all +select + m.date, + 'by_billing_country' as dimension, + d.main_billing_country_iso_3_per_deal as dimension_value, + sum(coalesce(m.total_revenue_in_gbp, 0)) / count(*) as expected_mrr_per_deal +from int_monthly_aggregated_metrics_history_by_deal m +inner join + deal_attributes d + on m.id_deal = d.id_deal + and date_trunc('month', m.date) >= date_trunc('month', d.effective_deal_start_month) + and date_trunc('month', m.date) + <= coalesce(d.hubspot_deal_cancellation_month, '2099-01-01') + and date_trunc('month', m.date)::date <> date_trunc('month', now())::date +where d.hubspot_listing_segmentation <> 'UNSET' +group by 1, 2, 3 +union all +select + m.date, + 'global' as dimension, + 'global' as dimension_value, + sum(coalesce(m.total_revenue_in_gbp, 0)) / count(*) as expected_mrr_per_deal +from int_monthly_aggregated_metrics_history_by_deal m +inner join + deal_attributes d + on m.id_deal = d.id_deal + and date_trunc('month', m.date) >= date_trunc('month', d.effective_deal_start_month) + and date_trunc('month', m.date) + <= coalesce(d.hubspot_deal_cancellation_month, '2099-01-01') + and date_trunc('month', m.date)::date <> date_trunc('month', now())::date +where d.hubspot_listing_segmentation <> 'UNSET' +group by 1, 2, 3 diff --git a/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql b/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql deleted file mode 100644 index 1f02314..0000000 --- a/models/intermediate/cross/int_mtd_agg_onboarding_mrr_metrics.sql +++ /dev/null @@ -1,67 +0,0 @@ -with - int_kpis__agg_daily_deals as ( - select date, dimension_value as hubspot_listing_segmentation, new_deals - from {{ ref("int_kpis__agg_daily_deals") }} - where dimension = 'by_number_of_listings' - ), - onboarding_mrr_metrics as ( - select - mom.date, - 'by_number_of_listings' as dimension, - mom.hubspot_listing_segmentation as dimension_value, - ad.number_of_new_deals, - mom.expected_mrr as expected_mrr_per_deal, - mom.expected_mrr * ad.number_of_new_deals as expected_mrr - from {{ ref("int_monthly_onboarding_mrr_metrics") }} mom - left join - int_kpis__agg_daily_deals ad - on mom.date = ad.date - and mom.hubspot_listing_segmentation = ad.hubspot_listing_segmentation - where - mom.main_billing_country_iso_3 = 'global' - and mom.hubspot_listing_segmentation <> 'global' - union all - select - date, - 'by_billing_country' as dimension, - main_billing_country_iso_3 as dimension_value, - null as number_of_new_deals, - expected_mrr as expected_mrr_per_deal, - null as expected_mrr - from {{ ref("int_monthly_onboarding_mrr_metrics") }} - where - hubspot_listing_segmentation = 'global' - and main_billing_country_iso_3 <> 'global' - union all - select - date, - 'global' as dimension, - 'global' as dimension_value, - null as number_of_new_deals, - expected_mrr as expected_mrr_per_deal, - null as expected_mrr - from {{ ref("int_monthly_onboarding_mrr_metrics") }} - where - hubspot_listing_segmentation = 'global' - and main_billing_country_iso_3 = 'global' - ), - global_expected_mrr as ( - select - omm.date, - 'global' as dimension, - sum(omm.number_of_new_deals) as number_of_new_deals, - sum(omm.number_of_new_deals * omm.expected_mrr_per_deal) as expected_mrr - from onboarding_mrr_metrics omm - where omm.dimension = 'by_number_of_listings' - group by 1, 2 - ) -select - omm.date, - omm.dimension, - omm.dimension_value, - coalesce(gem.number_of_new_deals, omm.number_of_new_deals) as number_of_new_deals, - omm.expected_mrr_per_deal, - coalesce(gem.expected_mrr, omm.expected_mrr) as expected_mrr -from onboarding_mrr_metrics omm -left join - global_expected_mrr gem on omm.date = gem.date and omm.dimension = gem.dimension diff --git a/models/intermediate/cross/int_mtd_agg_onboarding_mrr_revenue.sql b/models/intermediate/cross/int_mtd_agg_onboarding_mrr_revenue.sql new file mode 100644 index 0000000..f57c266 --- /dev/null +++ b/models/intermediate/cross/int_mtd_agg_onboarding_mrr_revenue.sql @@ -0,0 +1,31 @@ +with + int_kpis__agg_daily_deals as ( + select date, dimension_value as hubspot_listing_segmentation, new_deals + from {{ ref("int_kpis__agg_daily_deals") }} + where dimension = 'by_number_of_listings' + ), + number_of_listing_expected_mrr as ( + select + mom.date, + mom.dimension, + mom.dimension_value, + ad.new_deals as number_of_new_deals, + mom.expected_mrr_per_deal * ad.new_deals as expected_mrr + from {{ ref("int_monthly_onboarding_mrr_per_deal") }} mom + left join + int_kpis__agg_daily_deals ad + on mom.date = ad.date + and mom.dimension_value = ad.hubspot_listing_segmentation + where mom.dimension = 'by_number_of_listings' + ) +select * +from number_of_listing_expected_mrr +union all +select + date, + 'global' as dimension, + 'global' as dimension_value, + sum(number_of_new_deals) as number_of_new_deals, + sum(expected_mrr) as expected_mrr +from number_of_listing_expected_mrr +group by date diff --git a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql index e74653a..fbaf717 100644 --- a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql +++ b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql @@ -171,8 +171,11 @@ with dimension in ('global', 'by_number_of_listings', 'by_billing_country') and dimension_value <> 'UNSET' ), - int_mtd_agg_onboarding_mrr_metrics as ( - select * from {{ ref("int_mtd_agg_onboarding_mrr_metrics") }} + int_monthly_onboarding_mrr_per_deal as ( + select * from {{ ref("int_monthly_onboarding_mrr_per_deal") }} + ), + int_mtd_agg_onboarding_mrr_revenue as ( + select * from {{ ref("int_mtd_agg_onboarding_mrr_revenue") }} ), plain_kpi_combination as ( @@ -266,10 +269,9 @@ with as host_resolution_amount_paid_per_created_booking, {{ return_capped_value( - "cast(host_resolutions.xero_host_resolution_payment_count as decimal) - / created_bookings.created_bookings", + "cast(host_resolutions.xero_host_resolution_payment_count as decimal) / created_bookings.created_bookings", -1, - 1 + 1, ) }} as host_resolution_payment_per_created_booking_ratio, @@ -347,21 +349,12 @@ with ) as revenue_retained_in_gbp, {{ return_capped_value( - "nullif( - coalesce(guest_payments.total_guest_payments_in_gbp, 0) - + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) - + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) - + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0), - 0 - ) / nullif( - coalesce(guest_payments.total_guest_payments_in_gbp, 0) - + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) - + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), - 0 - )", + "nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0), 0 ) / nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), 0 )", -1, - 1 - )}} as revenue_retained_ratio, + 1, + ) + }} + as revenue_retained_ratio, -- INCOME RETAINED POST RESOLUTIONS-- nullif( @@ -374,27 +367,16 @@ with ) as revenue_retained_post_resolutions_in_gbp, {{ return_capped_value( - "nullif( - coalesce(guest_payments.total_guest_payments_in_gbp, 0) - + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) - + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) - + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0) - + coalesce(host_resolutions.xero_host_resolution_amount_paid_in_gbp, 0), - 0 - ) / nullif( - coalesce(guest_payments.total_guest_payments_in_gbp, 0) - + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) - + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), - 0 - )", + "nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0) + coalesce(host_resolutions.xero_host_resolution_amount_paid_in_gbp, 0), 0 ) / nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), 0 )", -1, - 1 + 1, ) - }} as revenue_retained_post_resolutions_ratio, + }} + as revenue_retained_post_resolutions_ratio, -- ONBOARDING MRR METRIC -- onboarding_mrr.expected_mrr_per_deal, - onboarding_mrr.expected_mrr + onboarding_mrr_revenue.expected_mrr from int_kpis__agg_dates_main_kpis d left join @@ -468,10 +450,15 @@ with and d.dimension = churn.dimension and d.dimension_value = churn.dimension_value left join - int_mtd_agg_onboarding_mrr_metrics onboarding_mrr + int_monthly_onboarding_mrr_per_deal onboarding_mrr on d.date = onboarding_mrr.date and d.dimension = onboarding_mrr.dimension and d.dimension_value = onboarding_mrr.dimension_value + left join + int_mtd_agg_onboarding_mrr_revenue onboarding_mrr_revenue + on d.date = onboarding_mrr_revenue.date + and d.dimension = onboarding_mrr_revenue.dimension + and d.dimension_value = onboarding_mrr_revenue.dimension_value ) select diff --git a/models/intermediate/cross/schema.yml b/models/intermediate/cross/schema.yml index 71cac76..419ed66 100644 --- a/models/intermediate/cross/schema.yml +++ b/models/intermediate/cross/schema.yml @@ -1707,7 +1707,7 @@ models: data_type: boolean description: "Flag to indicate if the deal is in Xero." - - name: int_monthly_onboarding_mrr_metrics + - name: int_monthly_onboarding_mrr_per_deal description: | "This table provides data on the Onboarding Monthly Recurring Revenue (MRR). The Onboarding MRR is an estimate of the expected monthly revenue generated by @@ -1719,68 +1719,40 @@ models: - dbt_utils.unique_combination_of_columns: combination_of_columns: - date - - main_billing_country_iso_3 - - hubspot_listing_segmentation + - dimension + - dimension_value columns: - name: date data_type: date - description: | - "Date representing the last day of the month. The metrics are calculated using data - from the 12 months leading up to and including this date. Along with - `main_billing_country_iso_3` and `hubspot_listing_segmentation`, this field serves - as part of the primary key for the model." - data_tests: - - not_null - - is_last_day_of_month - - - name: main_billing_country_iso_3 - data_type: text - description: | - "Main billing country code from ISO 3166" + description: The date for the month-to-date metrics. data_tests: - not_null - - name: hubspot_listing_segmentation - data_type: text - description: | - "Segmentation based on the number of properties specified by each deal - in HubSpot." + - name: dimension + data_type: string + description: The dimension or granularity of the metrics. data_tests: - - not_null - accepted_values: values: - - "01-05" - - "06-20" - - "21-60" - - "61+" - - "global" + - global + - by_number_of_listings + - by_billing_country - - name: total_revenue_in_gbp - data_type: numeric - description: | - "Total revenue accumulated by all active accounts over the last 12 months." + - name: dimension_value + data_type: string + description: The value or segment available for the selected dimension. data_tests: - not_null - - name: total_active_months - data_type: numeric - description: | - "Total number of active months for all accounts over the last 12 months." - data_tests: - - not_null - - dbt_expectations.expect_column_values_to_be_between: - min_value: 0 - strictly: false - - - name: expected_mrr + - name: expected_mrr_per_deal data_type: numeric description: | "Expected MRR for each new deal." data_tests: - not_null - - name: int_mtd_agg_onboarding_mrr_metrics + - name: int_mtd_agg_onboarding_mrr_revenue description: | This model contains the month-to-date aggregated metrics for the onboarding MRR. It includes the expected MRR per deal and the total expected MRR, which is obtained @@ -1820,10 +1792,6 @@ models: data_type: numeric description: Number of new deals in the month. - - name: expected_mrr_per_deal - data_type: numeric - description: Expected Onboarding MRR per new deal. - - name: expected_mrr data_type: numeric description: | From c0da375223d35ea2dec38d44e1cdde57af832e9e Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Wed, 29 Jan 2025 11:20:12 +0100 Subject: [PATCH 7/9] Update --- .../kpis/int_kpis__lifecycle_daily_deal.sql | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql b/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql index f621694..6189080 100644 --- a/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql +++ b/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql @@ -28,15 +28,27 @@ with booked_days_per_deal as ( select icuh.id_deal, - hd.live_date_utc as created_date_utc, - lag(hd.live_date_utc, 1) over ( - partition by icuh.id_deal order by hd.live_date_utc asc + icb.created_date_utc as created_date_utc, + lag(icb.created_date_utc, 1) over ( + partition by icuh.id_deal order by icb.created_date_utc asc ) as previous_booked_date from int_core__bookings icb inner join int_core__user_host icuh on icb.id_user_host = icuh.id_user_host inner join int_hubspot__deal hd on icuh.id_deal = hd.id_deal where icuh.id_deal is not null - group by icuh.id_deal, hd.live_date_utc + group by icuh.id_deal, icb.created_date_utc + ), + deals as ( + select + coalesce(hd.id_deal, h.id_deal) as id_deal, + min(coalesce(hd.live_date_utc, h.created_date_utc)) as created_date_utc + from intermediate.int_hubspot__deal hd + full outer join + intermediate.int_core__user_host h + on hd.id_deal = h.id_deal + and h.id_deal is not null + where hd.id_deal is not null + group by 1 ), deal_historic_booking_dates as ( select @@ -47,7 +59,7 @@ with max(b.created_date_utc) as last_time_booked_date_utc, max(b.previous_booked_date) as second_to_last_time_booked_date_utc from int_kpis__dimension_dates d - inner join int_core__user_host h on d.date >= h.created_date_utc + inner join deals h on d.date >= h.created_date_utc left join booked_days_per_deal b on h.id_deal = b.id_deal @@ -145,9 +157,7 @@ select case -- 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 + when deal_was_created_this_month and not deal_has_been_offboarded then '01-New' -- 02-Never Booked: The deal has been created before this month and has not -- had any booking. Additionally, the deal has not been offboarded in hubspot. From a48f6d0f5962a9a25370a8a5b37413dd5bd45352 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Wed, 29 Jan 2025 12:09:52 +0100 Subject: [PATCH 8/9] Fixed dumb auto formatting --- .../int_mtd_vs_previous_year_metrics.sql | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql index fbaf717..e7259cf 100644 --- a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql +++ b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql @@ -269,9 +269,10 @@ with as host_resolution_amount_paid_per_created_booking, {{ return_capped_value( - "cast(host_resolutions.xero_host_resolution_payment_count as decimal) / created_bookings.created_bookings", + "cast(host_resolutions.xero_host_resolution_payment_count as decimal) + / created_bookings.created_bookings", -1, - 1, + 1 ) }} as host_resolution_payment_per_created_booking_ratio, @@ -349,12 +350,22 @@ with ) as revenue_retained_in_gbp, {{ return_capped_value( - "nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0), 0 ) / nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), 0 )", + "nullif( + coalesce(guest_payments.total_guest_payments_in_gbp, 0) + + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0), + 0 + ) / nullif( + coalesce(guest_payments.total_guest_payments_in_gbp, 0) + + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), + 0 + )", -1, - 1, + 1 ) - }} - as revenue_retained_ratio, + }} as revenue_retained_ratio, -- INCOME RETAINED POST RESOLUTIONS-- nullif( @@ -367,12 +378,23 @@ with ) as revenue_retained_post_resolutions_in_gbp, {{ return_capped_value( - "nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0) + coalesce(host_resolutions.xero_host_resolution_amount_paid_in_gbp, 0), 0 ) / nullif( coalesce(guest_payments.total_guest_payments_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), 0 )", + "nullif( + coalesce(guest_payments.total_guest_payments_in_gbp, 0) + + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + + coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0) + + coalesce(host_resolutions.xero_host_resolution_amount_paid_in_gbp, 0), + 0 + ) / nullif( + coalesce(guest_payments.total_guest_payments_in_gbp, 0) + + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0), + 0 + )", -1, - 1, + 1 ) - }} - as revenue_retained_post_resolutions_ratio, + }} as revenue_retained_post_resolutions_ratio, -- ONBOARDING MRR METRIC -- onboarding_mrr.expected_mrr_per_deal, From 63b1eac81fdc5670f146cbc61adbbdd7688799e6 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Wed, 29 Jan 2025 15:44:07 +0100 Subject: [PATCH 9/9] Addressed comments --- .../cross/int_monthly_onboarding_mrr_per_deal.sql | 3 ++- models/intermediate/cross/schema.yml | 11 +++++++---- .../kpis/int_kpis__lifecycle_daily_deal.sql | 7 +++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/models/intermediate/cross/int_monthly_onboarding_mrr_per_deal.sql b/models/intermediate/cross/int_monthly_onboarding_mrr_per_deal.sql index 9f5181c..3368bb8 100644 --- a/models/intermediate/cross/int_monthly_onboarding_mrr_per_deal.sql +++ b/models/intermediate/cross/int_monthly_onboarding_mrr_per_deal.sql @@ -2,6 +2,7 @@ with int_monthly_aggregated_metrics_history_by_deal as ( select * from {{ ref("int_monthly_aggregated_metrics_history_by_deal") }} ), + int_kpis__dimension_deals as (select * from {{ ref("int_kpis__dimension_deals") }}), deal_attributes as ( select id_deal, @@ -13,7 +14,7 @@ with coalesce( hubspot_listing_segmentation, 'UNSET' ) as hubspot_listing_segmentation - from {{ ref("int_kpis__dimension_deals") }} + from int_kpis__dimension_deals -- Exclude deals without live dates where effective_deal_start_date_utc is not null ) diff --git a/models/intermediate/cross/schema.yml b/models/intermediate/cross/schema.yml index 419ed66..780921b 100644 --- a/models/intermediate/cross/schema.yml +++ b/models/intermediate/cross/schema.yml @@ -1754,9 +1754,13 @@ models: - name: int_mtd_agg_onboarding_mrr_revenue description: | - This model contains the month-to-date aggregated metrics for the onboarding MRR. - It includes the expected MRR per deal and the total expected MRR, which is obtained - by summing the expected MRRs for all new deals. + This model contains the month-to-date aggregated metrics for onboarding MRR. + It includes the total expected MRR revenue for the month, aggregated by + dimension for 'global' and 'by_number_of_listings' only. + - The 'by_number_of_listings' dimension is calculated by multiplying the + expected MRR per deal by the number of new deals in that segment. + - The 'global' dimension represents the sum of all expected MRRs across + all segments. data_tests: - dbt_utils.unique_combination_of_columns: @@ -1780,7 +1784,6 @@ models: values: - global - by_number_of_listings - - by_billing_country - name: dimension_value data_type: string diff --git a/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql b/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql index 6189080..53393f7 100644 --- a/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql +++ b/models/intermediate/kpis/int_kpis__lifecycle_daily_deal.sql @@ -34,7 +34,6 @@ with ) as previous_booked_date from int_core__bookings icb inner join int_core__user_host icuh on icb.id_user_host = icuh.id_user_host - inner join int_hubspot__deal hd on icuh.id_deal = hd.id_deal where icuh.id_deal is not null group by icuh.id_deal, icb.created_date_utc ), @@ -42,12 +41,12 @@ with select coalesce(hd.id_deal, h.id_deal) as id_deal, min(coalesce(hd.live_date_utc, h.created_date_utc)) as created_date_utc - from intermediate.int_hubspot__deal hd + from int_hubspot__deal hd full outer join - intermediate.int_core__user_host h + int_core__user_host h on hd.id_deal = h.id_deal - and h.id_deal is not null where hd.id_deal is not null + and h.id_deal is not null group by 1 ), deal_historic_booking_dates as (