Merged PR 3443: Switch of Xero metrics New KPIs flow - Invoiced Revenue and Host Resolutions

# Description

Switches Xero metrics to the new KPIs flow. This uses the 2 new entities around Invoiced Revenue and Host Resolutions.

The metrics affected will change computation source in PBI as well (for MTD per category and Monthly by deal views). This directly affects the following metrics:
* Invoiced Operator Revenue
* Invoiced Booking Fees Revenue
* Invoiced Listing Fees Revenue
* Invoiced Verification Fees Revenue
* Invoiced APIs Revenue
* Invoiced Athena Revenue
* Invoiced E-Deposit Revenue
* Damage Host-Waiver Payments
* Host Resolutions Amount Paid
* Host Resolutions Payment Count

Additionally, the following metrics will be indirectly affected since depend partially on Xero:
* Total Revenue
* 4x Total Revenue per (Booking Created, Guest Journey Created, Deals Booked in Month, Listings Booked in Month)
* Waiver Retained

# 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. **Same as last time - the way models are called could be improved, but let's switch everything first and then discuss. There's chances these cross models will die anyway**
- [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: #23759
This commit is contained in:
Oriol Roqué Paniagua 2024-11-07 07:48:38 +00:00
parent dc4f5098a1
commit 9ef9a57c03
2 changed files with 90 additions and 51 deletions

View file

@ -53,8 +53,15 @@ with
from {{ ref("int_kpis__agg_monthly_guest_payments") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
int_xero__monthly_invoicing_history_by_deal as (
select * from {{ ref("int_xero__monthly_invoicing_history_by_deal") }}
invoiced_revenue as (
select *
from {{ ref("int_kpis__agg_monthly_invoiced_revenue") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
host_resolutions as (
select *
from {{ ref("int_kpis__agg_monthly_host_resolutions") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
)
select
@ -103,27 +110,27 @@ select
accommodations.listings_booked_in_12_months,
-- HOST (OPERATOR) REVENUE --
invoicing.xero_booking_net_fees_in_gbp,
invoicing.xero_listing_net_fees_in_gbp,
invoicing.xero_verification_net_fees_in_gbp,
invoicing.xero_operator_net_fees_in_gbp,
invoiced_revenue.xero_booking_net_fees_in_gbp,
invoiced_revenue.xero_listing_net_fees_in_gbp,
invoiced_revenue.xero_verification_net_fees_in_gbp,
invoiced_revenue.xero_operator_net_fees_in_gbp,
-- APIs REVENUE --
invoicing.xero_apis_net_fees_in_gbp,
invoicing.xero_e_deposit_net_fees_in_gbp,
invoicing.xero_guesty_net_fees_in_gbp,
invoiced_revenue.xero_apis_net_fees_in_gbp,
invoiced_revenue.xero_e_deposit_net_fees_in_gbp,
invoiced_revenue.xero_guesty_net_fees_in_gbp,
-- HOST RESOLUTIONS --
invoicing.xero_host_resolution_amount_paid_in_gbp,
invoicing.xero_host_resolution_payment_count,
host_resolutions.xero_host_resolution_amount_paid_in_gbp,
host_resolutions.xero_host_resolution_payment_count,
-- GUEST REVENUE AND PAYMENTS --
guest_payments.deposit_fees_in_gbp,
guest_payments.waiver_payments_in_gbp,
invoicing.xero_waiver_paid_back_to_host_in_gbp,
invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp,
nullif(
coalesce(guest_payments.waiver_payments_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0),
+ coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0),
0
) as waiver_net_fees_in_gbp,
guest_payments.checkin_cover_fees_in_gbp,
@ -132,8 +139,8 @@ select
-- TOTAL REVENUE --
nullif(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0),
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0),
0
) as total_revenue_in_gbp,
@ -148,21 +155,21 @@ select
-- TOTAL REVENUE WEIGHTED METRICS --
(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
)
/ nullif(created_bookings.created_bookings, 0) as total_revenue_per_created_booking,
(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
) / nullif(
created_guest_journeys.created_guest_journeys, 0
) as total_revenue_per_created_guest_journey,
(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
) / nullif(
accommodations.listings_booked_in_month, 0
) as total_revenue_per_listings_booked_in_month
@ -213,6 +220,10 @@ left join
on d.date = accommodations.date
and d.id_deal = accommodations.id_deal
left join
int_xero__monthly_invoicing_history_by_deal invoicing
on d.date = invoicing.date
and d.id_deal = invoicing.id_deal
invoiced_revenue
on d.date = invoiced_revenue.end_date
and d.id_deal = invoiced_revenue.dimension_value
left join
host_resolutions
on d.date = host_resolutions.end_date
and d.id_deal = host_resolutions.dimension_value

View file

@ -125,8 +125,31 @@ with
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
int_xero__mtd_invoicing_metrics as (
select * from {{ ref("int_xero__mtd_invoicing_metrics") }}
invoiced_revenue as (
select *
from {{ ref("int_kpis__agg_mtd_invoiced_revenue") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__agg_monthly_invoiced_revenue") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
host_resolutions as (
select *
from {{ ref("int_kpis__agg_mtd_host_resolutions") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__agg_monthly_host_resolutions") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
int_monthly_churn_metrics as (select * from {{ ref("int_monthly_churn_metrics") }}),
int_dates_mtd_by_dimension as (
@ -196,27 +219,27 @@ with
accommodations.listings_booked_in_12_months,
-- HOST (OPERATOR) REVENUE --
invoicing.xero_booking_net_fees_in_gbp,
invoicing.xero_listing_net_fees_in_gbp,
invoicing.xero_verification_net_fees_in_gbp,
invoicing.xero_operator_net_fees_in_gbp,
invoiced_revenue.xero_booking_net_fees_in_gbp,
invoiced_revenue.xero_listing_net_fees_in_gbp,
invoiced_revenue.xero_verification_net_fees_in_gbp,
invoiced_revenue.xero_operator_net_fees_in_gbp,
-- APIs REVENUE --
invoicing.xero_apis_net_fees_in_gbp,
invoicing.xero_e_deposit_net_fees_in_gbp,
invoicing.xero_guesty_net_fees_in_gbp,
invoiced_revenue.xero_apis_net_fees_in_gbp,
invoiced_revenue.xero_e_deposit_net_fees_in_gbp,
invoiced_revenue.xero_guesty_net_fees_in_gbp,
-- HOST RESOLUTIONS --
invoicing.xero_host_resolution_amount_paid_in_gbp,
invoicing.xero_host_resolution_payment_count,
host_resolutions.xero_host_resolution_amount_paid_in_gbp,
host_resolutions.xero_host_resolution_payment_count,
-- GUEST REVENUE AND PAYMENTS --
guest_payments.deposit_fees_in_gbp,
guest_payments.waiver_payments_in_gbp,
invoicing.xero_waiver_paid_back_to_host_in_gbp,
invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp,
nullif(
coalesce(guest_payments.waiver_payments_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0),
+ coalesce(invoiced_revenue.xero_waiver_paid_back_to_host_in_gbp, 0),
0
) as waiver_net_fees_in_gbp,
guest_payments.checkin_cover_fees_in_gbp,
@ -225,8 +248,8 @@ with
-- TOTAL REVENUE --
nullif(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0),
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0),
0
) as total_revenue_in_gbp,
@ -241,29 +264,29 @@ with
-- TOTAL REVENUE WEIGHTED METRICS --
(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
) / nullif(
created_bookings.created_bookings, 0
) as total_revenue_per_created_booking,
(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
) / nullif(
created_guest_journeys.created_guest_journeys, 0
) as total_revenue_per_created_guest_journey,
(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
) / nullif(
deals.deals_booked_in_month, 0
) as total_revenue_per_deals_booked_in_month,
(
coalesce(guest_payments.total_guest_payments_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
) / nullif(
accommodations.listings_booked_in_month, 0
) as total_revenue_per_listings_booked_in_month,
@ -330,10 +353,15 @@ with
and d.dimension = guest_payments.dimension
and d.dimension_value = guest_payments.dimension_value
left join
int_xero__mtd_invoicing_metrics invoicing
on d.date = invoicing.date
and d.dimension = invoicing.dimension
and d.dimension_value = invoicing.dimension_value
invoiced_revenue
on d.date = invoiced_revenue.end_date
and d.dimension = invoiced_revenue.dimension
and d.dimension_value = invoiced_revenue.dimension_value
left join
host_resolutions
on d.date = host_resolutions.end_date
and d.dimension = host_resolutions.dimension
and d.dimension_value = host_resolutions.dimension_value
left join
int_monthly_churn_metrics churn
on d.date = churn.date