Merged PR 4439: First version of int_ytd_mtd_main_metrics_overview

# Description

New model for the purpose of Main KPIs - Overview.

It computes:
* Current MTD value
* Previous Month EOM value
* Previous Year MTD value (12 months ago)
* Current YTD value
* Previous Year YTD value

for the metrics:
* Total Revenue
* Revenue Retained Post-Resolutions
* Guest Revenue
* Invoiced Operator Revenue
* Invoiced APIs Revenue
* Host Resolutions Amount Paid
* Damage Host Waiver Payments
* Billable Bookings
* New Deals
* Churning Deals
* Live Deals (dedicated logic handling)
* Waiver Revenue

Additionally it properly computes the following derived metrics:
* Waiver Payout Rate
* Resolutions Payout Rate
* Operator Revenue per Billable Booking
* Waiver Revenue per Billable Booking

Only for dimension = 'global', though should be easy to extend to other dimensions.

This does not handle (yet) Onboarding MRR nor Revenue Churn Rate, mostly because I need to think how this can be properly attributed in a YTD basis.
This does not compute variations (abs. diff. or rel. diff.) yet.
This does not handle the "hiding" of invoicing metrics due to the invoicing cycle yet.
This does not handle targets... yet!

# 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: #27609
This commit is contained in:
Oriol Roqué Paniagua 2025-02-18 14:30:12 +00:00
parent 6e26a2a761
commit 073620bd3d
2 changed files with 674 additions and 0 deletions

View file

@ -0,0 +1,309 @@
with
int_mtd_vs_previous_year_metrics as (
select * from {{ ref("int_mtd_vs_previous_year_metrics") }}
),
mtd_main_metrics_overview as (
select
-- Time-based attributes --
year as calendar_year,
case
when month >= 4
then year + 1 -- Financial Year labeled by the next year
else year -- Financial Year labeled by the current year
end as financial_year,
date,
previous_year_date,
-- Dimension/Value --
dimension,
dimension_value,
-- Current Month, Month To Date Metrics --
total_revenue_in_gbp as current_month_mtd_total_revenue_in_gbp,
revenue_retained_post_resolutions_in_gbp
as current_month_mtd_revenue_retained_post_resolutions_in_gbp,
total_guest_payments_in_gbp
as current_month_mtd_total_guest_payments_in_gbp,
xero_operator_net_fees_in_gbp
as current_month_mtd_xero_operator_net_fees_in_gbp,
xero_apis_net_fees_in_gbp as current_month_mtd_xero_apis_net_fees_in_gbp,
xero_host_resolution_amount_paid_in_gbp
as current_month_mtd_xero_host_resolution_amount_paid_in_gbp,
xero_waiver_paid_back_to_host_in_gbp
as current_month_mtd_xero_waiver_paid_back_to_host_in_gbp,
billable_bookings as current_month_mtd_billable_bookings,
new_deals as current_month_mtd_new_deals,
churning_deals as current_month_mtd_churning_deals,
live_deals as current_month_mtd_live_deals,
waiver_payments_in_gbp as current_month_mtd_waiver_payments_in_gbp,
-- Previous Year (12 months ago), Month To Date Metrics --
previous_year_total_revenue_in_gbp
as previous_year_mtd_total_revenue_in_gbp,
previous_year_revenue_retained_post_resolutions_in_gbp
as previous_year_mtd_revenue_retained_post_resolutions_in_gbp,
previous_year_total_guest_payments_in_gbp
as previous_year_mtd_total_guest_payments_in_gbp,
previous_year_xero_operator_net_fees_in_gbp
as previous_year_mtd_xero_operator_net_fees_in_gbp,
previous_year_xero_apis_net_fees_in_gbp
as previous_year_mtd_xero_apis_net_fees_in_gbp,
previous_year_xero_host_resolution_amount_paid_in_gbp
as previous_year_mtd_xero_host_resolution_amount_paid_in_gbp,
previous_year_xero_waiver_paid_back_to_host_in_gbp
as previous_year_mtd_xero_waiver_paid_back_to_host_in_gbp,
previous_year_billable_bookings as previous_year_mtd_billable_bookings,
previous_year_new_deals as previous_year_mtd_new_deals,
previous_year_churning_deals as previous_year_mtd_churning_deals,
previous_year_live_deals as previous_year_mtd_live_deals,
previous_year_waiver_payments_in_gbp
as previous_year_mtd_waiver_payments_in_gbp,
-- Previous Month, End Of Month Metrics --
lag(total_revenue_in_gbp) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_total_revenue_in_gbp,
lag(revenue_retained_post_resolutions_in_gbp) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_revenue_retained_post_resolutions_in_gbp,
lag(total_guest_payments_in_gbp) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_total_guest_payments_in_gbp,
lag(xero_operator_net_fees_in_gbp) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_xero_operator_net_fees_in_gbp,
lag(xero_apis_net_fees_in_gbp) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_xero_apis_net_fees_in_gbp,
lag(xero_host_resolution_amount_paid_in_gbp) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_xero_host_resolution_amount_paid_in_gbp,
lag(xero_waiver_paid_back_to_host_in_gbp) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_xero_waiver_paid_back_to_host_in_gbp,
lag(billable_bookings) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_billable_bookings,
lag(new_deals) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_new_deals,
lag(churning_deals) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_churning_deals,
lag(live_deals) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_live_deals,
lag(waiver_payments_in_gbp) over (
partition by dimension, dimension_value order by date
) as previous_month_eom_waiver_payments_in_gbp
from int_mtd_vs_previous_year_metrics
where
is_end_of_month_or_yesterday = true
-- Keeping only global dimension to start with
and dimension = 'global'
),
ytd_mtd_main_metrics_overview as (
select
-- Keep all Time Attributes, Dimension/Value and Month/MTD metrics
*,
-- Current Financial Year, Year To Date Metrics
sum(current_month_mtd_total_revenue_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_total_revenue_in_gbp,
sum(current_month_mtd_revenue_retained_post_resolutions_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_revenue_retained_post_resolutions_in_gbp,
sum(current_month_mtd_total_guest_payments_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_total_guest_payments_in_gbp,
sum(current_month_mtd_xero_operator_net_fees_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_xero_operator_net_fees_in_gbp,
sum(current_month_mtd_xero_apis_net_fees_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_xero_apis_net_fees_in_gbp,
sum(current_month_mtd_xero_host_resolution_amount_paid_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_xero_host_resolution_amount_paid_in_gbp,
sum(current_month_mtd_xero_waiver_paid_back_to_host_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_xero_waiver_paid_back_to_host_in_gbp,
sum(current_month_mtd_billable_bookings) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_billable_bookings,
sum(current_month_mtd_new_deals) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_new_deals,
sum(current_month_mtd_churning_deals) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_churning_deals,
sum(current_month_mtd_waiver_payments_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as current_ytd_waiver_payments_in_gbp,
-- Specific treatment for live_deals as it is a counter
current_month_mtd_live_deals as current_ytd_live_deals,
-- Previous Financial Year, Year To Date Metrics
sum(previous_year_mtd_total_revenue_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_total_revenue_in_gbp,
sum(previous_year_mtd_revenue_retained_post_resolutions_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_revenue_retained_post_resolutions_in_gbp,
sum(previous_year_mtd_total_guest_payments_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_total_guest_payments_in_gbp,
sum(previous_year_mtd_xero_operator_net_fees_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_xero_operator_net_fees_in_gbp,
sum(previous_year_mtd_xero_apis_net_fees_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_xero_apis_net_fees_in_gbp,
sum(previous_year_mtd_xero_host_resolution_amount_paid_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_xero_host_resolution_amount_paid_in_gbp,
sum(previous_year_mtd_xero_waiver_paid_back_to_host_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_xero_waiver_paid_back_to_host_in_gbp,
sum(previous_year_mtd_billable_bookings) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_billable_bookings,
sum(previous_year_mtd_new_deals) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_new_deals,
sum(previous_year_mtd_churning_deals) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_churning_deals,
sum(previous_year_mtd_waiver_payments_in_gbp) over (
partition by financial_year, dimension, dimension_value
order by date
rows between unbounded preceding and current row
) as previous_ytd_waiver_payments_in_gbp,
-- Specific treatment for live_deals as it is a counter
previous_year_mtd_live_deals as previous_ytd_live_deals
from mtd_main_metrics_overview
)
select
-- Keep all Time Attributes, Dimension/Value, Month/MTD metrics and YTD metrics
*,
-- Compute Derived Metrics --
-- Current Month, Month To Date Metrics --
abs(coalesce(current_month_mtd_xero_waiver_paid_back_to_host_in_gbp, 0)) / nullif(
current_month_mtd_waiver_payments_in_gbp, 0
) as current_month_mtd_waiver_payout_rate,
abs(
coalesce(current_month_mtd_xero_host_resolution_amount_paid_in_gbp, 0)
) / nullif(
current_month_mtd_total_revenue_in_gbp, 0
) as current_month_mtd_resolutions_payout_rate,
coalesce(current_month_mtd_xero_operator_net_fees_in_gbp, 0) / nullif(
current_month_mtd_billable_bookings, 0
) as current_month_mtd_operator_revenue_per_billable_booking,
coalesce(current_month_mtd_waiver_payments_in_gbp, 0) / nullif(
current_month_mtd_billable_bookings, 0
) as current_month_mtd_waiver_revenue_per_billable_booking,
-- Previous Year (12 months ago), Month To Date Metrics --
abs(coalesce(previous_year_mtd_xero_waiver_paid_back_to_host_in_gbp, 0)) / nullif(
previous_year_mtd_waiver_payments_in_gbp, 0
) as previous_year_mtd_waiver_payout_rate,
abs(
coalesce(previous_year_mtd_xero_host_resolution_amount_paid_in_gbp, 0)
) / nullif(
previous_year_mtd_total_revenue_in_gbp, 0
) as previous_year_mtd_resolutions_payout_rate,
coalesce(previous_year_mtd_xero_operator_net_fees_in_gbp, 0) / nullif(
previous_year_mtd_billable_bookings, 0
) as previous_year_mtd_operator_revenue_per_billable_booking,
coalesce(previous_year_mtd_waiver_payments_in_gbp, 0) / nullif(
previous_year_mtd_billable_bookings, 0
) as previous_year_mtd_waiver_revenue_per_billable_booking,
-- Previous Month, End Of Month Metrics --
abs(coalesce(previous_month_eom_xero_waiver_paid_back_to_host_in_gbp, 0)) / nullif(
previous_month_eom_waiver_payments_in_gbp, 0
) as previous_month_eom_waiver_payout_rate,
abs(
coalesce(previous_month_eom_xero_host_resolution_amount_paid_in_gbp, 0)
) / nullif(
previous_month_eom_total_revenue_in_gbp, 0
) as previous_month_eom_resolutions_payout_rate,
coalesce(previous_month_eom_xero_operator_net_fees_in_gbp, 0) / nullif(
previous_month_eom_billable_bookings, 0
) as previous_month_eom_operator_revenue_per_billable_booking,
coalesce(previous_month_eom_waiver_payments_in_gbp, 0) / nullif(
previous_month_eom_billable_bookings, 0
) as previous_month_eom_waiver_revenue_per_billable_booking,
-- Current Financial Year, Year To Date Metrics --
abs(coalesce(current_ytd_xero_waiver_paid_back_to_host_in_gbp, 0))
/ nullif(current_ytd_waiver_payments_in_gbp, 0) as current_ytd_waiver_payout_rate,
abs(coalesce(current_ytd_xero_host_resolution_amount_paid_in_gbp, 0)) / nullif(
current_ytd_total_revenue_in_gbp, 0
) as current_ytd_resolutions_payout_rate,
coalesce(current_ytd_xero_operator_net_fees_in_gbp, 0) / nullif(
current_ytd_billable_bookings, 0
) as current_ytd_operator_revenue_per_billable_booking,
coalesce(current_ytd_waiver_payments_in_gbp, 0) / nullif(
current_ytd_billable_bookings, 0
) as current_ytd_waiver_revenue_per_billable_booking,
-- Previous Financial Year, Year To Date Metrics --
abs(coalesce(previous_ytd_xero_waiver_paid_back_to_host_in_gbp, 0))
/ nullif(previous_ytd_waiver_payments_in_gbp, 0) as previous_ytd_waiver_payout_rate,
abs(coalesce(previous_ytd_xero_host_resolution_amount_paid_in_gbp, 0)) / nullif(
previous_ytd_total_revenue_in_gbp, 0
) as previous_ytd_resolutions_payout_rate,
coalesce(previous_ytd_xero_operator_net_fees_in_gbp, 0) / nullif(
previous_ytd_billable_bookings, 0
) as previous_ytd_operator_revenue_per_billable_booking,
coalesce(previous_ytd_waiver_payments_in_gbp, 0) / nullif(
previous_ytd_billable_bookings, 0
) as previous_ytd_waiver_revenue_per_billable_booking
from ytd_mtd_main_metrics_overview