Merged PR 4935: KPIs Refactor Stage 4 - Onboarding MRR model in KPIs

# Description

Creates a single model in KPIs, aggregated by dimension/dimension value, in a monthly basis; named: `int_kpis__agg_monthly_onboarding_mrr`.

Attention! This substitutes both current models, namely `int_monthly_onboarding_mrr_per_deal` and `int_mtd_agg_onboarding_mrr_revenue`. However, both models are currently used to retrieve data for Main KPIs. I just combined both into one, so it will simplify also the gathering of data later on.

Note that this model is special in the sense that the onboarding mrr per deal is computed for global, listing segmentation and billing country dimensions; while the total onboarding mrr is only done for global and listing segmentation (as it's based on the number of listings segmentation for the total compute).

This has been tested with dbt audit helper and md5. This has been a bit more complex since it's comparing 1 new model vs 2 existing models. For reference, this is the md5 comparison used:

```
SELECT md5(array_agg(md5((t1.*)::varchar))::varchar)
  FROM (
        SELECT
        	mrr.date,
        	mrr.dimension,
        	mrr.dimension_value,
        	mrr.expected_mrr_per_deal,
        	total.number_of_new_deals,
        	total.expected_mrr as total_expected_mrr
          FROM intermediate.int_monthly_onboarding_mrr_per_deal mrr
          left join intermediate.int_mtd_agg_onboarding_mrr_revenue total
          on mrr.date = total.date
          and mrr.dimension = total.dimension
          and mrr.dimension_value = total.dimension_value
         ORDER BY date, dimension, dimension_value
       ) AS t1
union all
SELECT md5(array_agg(md5((t2.*)::varchar))::varchar)
  FROM (
        SELECT *
          FROM intermediate.int_kpis__agg_monthly_onboarding_mrr
         ORDER BY date, dimension, dimension_value
       ) AS t2
```

# 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.
- [X] I have checked for DRY opportunities with other models and docs.
- [X] 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: #27120, #28949
This commit is contained in:
Oriol Roqué Paniagua 2025-04-07 12:27:28 +00:00
parent 446bd7f7d3
commit dc8eee7128
3 changed files with 195 additions and 1 deletions

View file

@ -8701,3 +8701,79 @@ models:
- name: listings_booked_in_month_churn_average_contribution
data_type: numeric
description: Listings Booked in Month churn rate (average approach).
- name: int_kpis__agg_monthly_onboarding_mrr
description: |
This model contains the monthly aggregated metrics for onboarding MRR.
These metrics refer to the expectation of how much revenue is expected to
be generated from new deals, in average, in a monthly basis. This is a
projected value. Since Revenue is not a timely figure, the onboarding MRR
is shifted by one month. Keep in mind that the number of new deals are
the actual new deals onboarded in the month.
The metrics computed for this model are as follows:
- onboarding_mrr_per_new_deal_in_gbp: How much revenue in a month is expected
to be generated by a new deal?
- total_onboarding_mrr_in_gbp: How much revenue in a month is expected to be
generated by ALL new deals onboarded on that same month?
Additionally, it also contains "new_deals_count" for information purposes.
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 monthly metrics, corresponding to the EOM.
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: new_deals_count
data_type: numeric
description: Number of new deals in the month, for information purposes.
- name: onboarding_mrr_per_new_deal_in_gbp
data_type: numeric
description: |
Expected onboarding MRR per new deal in GBP.
This is computed by:
- Gathering all live deals that have a hubspot listing segmentation available.
- Retrieving the total revenue of these deals in a given month.
- Dividing the total revenue by the number of live deals.
This is assumed to be the expected onboarding MRR per each new deal.
data_tests:
- not_null
- name: total_onboarding_mrr_in_gbp
data_type: numeric
description: |
Total expected Onboarding MRR in GBP per date, dimension and dimension value.
This is computed by:
- Gathering the expected onboarding MRR per new deal for the dimension 'by_number_of_listings'
- Gathering the number of new deals for the dimension 'by_number_of_listings'
- Multiplying the two values, to get the total onboarding MRR for each listing segment
- Rolling up the total onboarding MRR for each listing segment to get the total onboarding MRR
for the Global dimension.
This is not available for 'by_billing_country' dimension, thus null values are expected.