Merged PR 3169: Adding Churn metrics to Global KPIs

# Description

Main changes:
- Creation of `int_monthly_churn_metrics` model. This follows a similar approach as for mtd models, with jinja loops to aggregate the metrics at different dimensions. This reads from the previous monthly model, thus creating a dependency on Global KPIs with By Deal KPIs.
- Adds the 6 metrics in the main aggregated model of Global KPIs `int_mtd_vs_previous_year_metrics`. It doesn't necessarily mean that the 6 metrics will be made available in the report.

This does NOT display these metrics in the report, and won't be done until deal lifecycle is enriched to consider hubspot offboarding in the state "05-Churning".

# 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: #22691
This commit is contained in:
Oriol Roqué Paniagua 2024-10-15 10:46:56 +00:00
parent 901be930df
commit 9440e6d624
3 changed files with 238 additions and 1 deletions

View file

@ -31,6 +31,7 @@ with
int_xero__mtd_invoicing_metrics as (
select * from {{ ref("int_xero__mtd_invoicing_metrics") }}
),
int_monthly_churn_metrics as (select * from {{ ref("int_monthly_churn_metrics") }}),
int_dates_mtd_by_dimension as (
select * from {{ ref("int_dates_mtd_by_dimension") }}
),
@ -159,7 +160,15 @@ with
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
) / nullif(
accommodations.listings_booked_in_month, 0
) as total_revenue_per_listings_booked_in_month
) as total_revenue_per_listings_booked_in_month,
-- CHURN --
churn.total_revenue_churn_additive_contribution,
churn.created_bookings_churn_additive_contribution,
churn.listings_booked_in_month_churn_additive_contribution,
churn.total_revenue_churn_average_contribution,
churn.created_bookings_churn_average_contribution,
churn.listings_booked_in_month_churn_average_contribution
from int_dates_mtd_by_dimension d
left join
@ -207,6 +216,11 @@ with
on d.date = invoicing.date
and d.dimension = invoicing.dimension
and d.dimension_value = invoicing.dimension_value
left join
int_monthly_churn_metrics churn
on d.date = churn.date
and d.dimension = churn.dimension
and d.dimension_value = churn.dimension_value
)
select
current.year,
@ -302,6 +316,30 @@ select
calculate_safe_relative_increment(
"total_revenue_per_listings_booked_in_month"
)
}},
-- CHURN --
{{ calculate_safe_relative_increment("total_revenue_churn_additive_contribution") }},
{{
calculate_safe_relative_increment(
"created_bookings_churn_additive_contribution"
)
}},
{{
calculate_safe_relative_increment(
"listings_booked_in_month_churn_additive_contribution"
)
}},
{{ calculate_safe_relative_increment("total_revenue_churn_average_contribution") }},
{{
calculate_safe_relative_increment(
"created_bookings_churn_average_contribution"
)
}},
{{
calculate_safe_relative_increment(
"listings_booked_in_month_churn_average_contribution"
)
}}
from plain_kpi_combination current