Update mtd_aggregated_metrics

This commit is contained in:
Joaquin Ossa 2024-09-16 16:01:49 +02:00
parent 2c17df3742
commit 54af8af30e
4 changed files with 63 additions and 56 deletions

View file

@ -11,7 +11,7 @@ with
select * from {{ ref("int_core__verification_requests") }} select * from {{ ref("int_core__verification_requests") }}
), ),
int_core__verification_payments as ( int_core__verification_payments as (
select * from {{ ref("int_core__verification_payments") }} select * from {{ ref("int_core__verification_payments", version=2) }}
), ),
int_core__user_host as (select * from {{ ref("int_core__user_host") }}), int_core__user_host as (select * from {{ ref("int_core__user_host") }}),
int_core__mtd_accommodation_segmentation as ( int_core__mtd_accommodation_segmentation as (

View file

@ -11,7 +11,7 @@ This model provides Month-To-Date (MTD) based on Guest Revenue metrics.
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
with with
int_core__verification_payments as ( int_core__verification_payments as (
select * from {{ ref("int_core__verification_payments") }} select * from {{ ref("int_core__verification_payments", version=2) }}
), ),
int_core__verification_requests as ( int_core__verification_requests as (
select * from {{ ref("int_core__verification_requests") }} select * from {{ ref("int_core__verification_requests") }}
@ -37,28 +37,28 @@ with
when when
upper(vp.verification_payment_type) upper(vp.verification_payment_type)
in {{ deposit_fees_verification_payment_type_items }} in {{ deposit_fees_verification_payment_type_items }}
then vp.amount_in_gbp then vp.amount_without_taxes_in_gbp
else null else null
end end
) as deposit_fees_in_gbp, ) as deposit_fees_without_taxes_in_gbp,
sum( sum(
case case
when when
upper(vp.verification_payment_type) upper(vp.verification_payment_type)
in {{ waiver_fees_verification_payment_type_items }} in {{ waiver_fees_verification_payment_type_items }}
then vp.amount_in_gbp then vp.amount_without_taxes_in_gbp
else null else null
end end
) as waiver_payments_in_gbp, ) as waiver_payments_without_taxes_in_gbp,
sum( sum(
case case
when when
upper(vp.verification_payment_type) upper(vp.verification_payment_type)
in {{ checkin_cover_fees_verification_payment_type_items }} in {{ checkin_cover_fees_verification_payment_type_items }}
then vp.amount_in_gbp then vp.amount_without_taxes_in_gbp
else null else null
end end
) as checkin_cover_fees_in_gbp ) as checkin_cover_fees_without_taxes_in_gbp
from int_dates_mtd d from int_dates_mtd d
inner join inner join
int_core__verification_payments vp int_core__verification_payments vp
@ -94,15 +94,21 @@ select
d.dimension_value, d.dimension_value,
d.is_end_of_month, d.is_end_of_month,
d.is_current_month, d.is_current_month,
nullif(gpym.deposit_fees_in_gbp, 0) as deposit_fees_in_gbp,
nullif(gpym.waiver_payments_in_gbp, 0) as waiver_payments_in_gbp,
nullif(gpym.checkin_cover_fees_in_gbp, 0) as checkin_cover_fees_in_gbp,
nullif( nullif(
coalesce(gpym.deposit_fees_in_gbp, 0) gpym.deposit_fees_without_taxes_in_gbp, 0
+ coalesce(gpym.waiver_payments_in_gbp, 0) ) as deposit_fees_without_taxes_in_gbp,
+ coalesce(gpym.checkin_cover_fees_in_gbp, 0), nullif(
gpym.waiver_payments_without_taxes_in_gbp, 0
) as waiver_payments_without_taxes_in_gbp,
nullif(
gpym.checkin_cover_fees_without_taxes_in_gbp, 0
) as checkin_cover_fees_without_taxes_in_gbp,
nullif(
coalesce(gpym.deposit_fees_without_taxes_in_gbp, 0)
+ coalesce(gpym.waiver_payments_without_taxes_in_gbp, 0)
+ coalesce(gpym.checkin_cover_fees_without_taxes_in_gbp, 0),
0 0
) as total_guest_payments_in_gbp ) as total_guest_payments_without_taxes_in_gbp
from int_dates_mtd_by_dimension d from int_dates_mtd_by_dimension d
left join left join
guest_payments_year_month gpym guest_payments_year_month gpym

View file

@ -362,18 +362,18 @@
{ {
"order_by": 260, "order_by": 260,
"metric": "Deposit Fees", "metric": "Deposit Fees",
"value": "deposit_fees_in_gbp", "value": "deposit_fees_without_taxes_in_gbp",
"previous_year_value": "previous_year_deposit_fees_in_gbp", "previous_year_value": "previous_year_deposit_fees_without_taxes_in_gbp",
"relative_increment": "relative_increment_deposit_fees_in_gbp", "relative_increment": "relative_increment_deposit_fees_without_taxes_in_gbp",
"number_format": "currency_gbp", "number_format": "currency_gbp",
"increment_sign_format": "positive", "increment_sign_format": "positive",
}, },
{ {
"order_by": 262, "order_by": 262,
"metric": "Waiver Amount Paid by Guests", "metric": "Waiver Amount Paid by Guests",
"value": "waiver_payments_in_gbp", "value": "waiver_payments_without_taxes_in_gbp",
"previous_year_value": "previous_year_waiver_payments_in_gbp", "previous_year_value": "previous_year_waiver_payments_without_taxes_in_gbp",
"relative_increment": "relative_increment_waiver_payments_in_gbp", "relative_increment": "relative_increment_waiver_payments_without_taxes_in_gbp",
"number_format": "currency_gbp", "number_format": "currency_gbp",
"increment_sign_format": "positive", "increment_sign_format": "positive",
}, },
@ -398,9 +398,9 @@
{ {
"order_by": 265, "order_by": 265,
"metric": "Check-In Hero Amount Paid by Guests", "metric": "Check-In Hero Amount Paid by Guests",
"value": "checkin_cover_fees_in_gbp", "value": "checkin_cover_fees_without_taxes_in_gbp",
"previous_year_value": "previous_year_checkin_cover_fees_in_gbp", "previous_year_value": "previous_year_checkin_cover_fees_without_taxes_in_gbp",
"relative_increment": "relative_increment_checkin_cover_fees_in_gbp", "relative_increment": "relative_increment_checkin_cover_fees_without_taxes_in_gbp",
"number_format": "currency_gbp", "number_format": "currency_gbp",
"increment_sign_format": "positive", "increment_sign_format": "positive",
}, },
@ -416,9 +416,9 @@
{ {
"order_by": 290, "order_by": 290,
"metric": "Guest Payments", "metric": "Guest Payments",
"value": "total_guest_payments_in_gbp", "value": "total_guest_payments_without_taxes_in_gbp",
"previous_year_value": "previous_year_total_guest_payments_in_gbp", "previous_year_value": "previous_year_total_guest_payments_without_taxes_in_gbp",
"relative_increment": "relative_increment_total_guest_payments_in_gbp", "relative_increment": "relative_increment_total_guest_payments_without_taxes_in_gbp",
"number_format": "currency_gbp", "number_format": "currency_gbp",
"increment_sign_format": "positive", "increment_sign_format": "positive",
}, },

View file

@ -2,7 +2,6 @@
This model pivots the data of the different mtd metrics models to get This model pivots the data of the different mtd metrics models to get
previous year for each line & computing relative increment. -- previous year for each line & computing relative increment. --
*/ */
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
with with
int_core__mtd_booking_metrics as ( int_core__mtd_booking_metrics as (
@ -23,7 +22,9 @@ with
int_xero__mtd_invoicing_metrics as ( int_xero__mtd_invoicing_metrics as (
select * from {{ ref("int_xero__mtd_invoicing_metrics") }} select * from {{ ref("int_xero__mtd_invoicing_metrics") }}
), ),
int_dates_mtd_by_dimension as (select * from {{ ref("int_dates_mtd_by_dimension") }}), int_dates_mtd_by_dimension as (
select * from {{ ref("int_dates_mtd_by_dimension") }}
),
plain_kpi_combination as ( plain_kpi_combination as (
@ -94,25 +95,25 @@ with
invoicing.xero_host_resolution_payment_count, invoicing.xero_host_resolution_payment_count,
-- GUEST REVENUE AND PAYMENTS -- -- GUEST REVENUE AND PAYMENTS --
guest_payments.deposit_fees_in_gbp, guest_payments.deposit_fees_without_taxes_in_gbp,
guest_payments.waiver_payments_in_gbp, guest_payments.waiver_payments_without_taxes_in_gbp,
invoicing.xero_waiver_paid_back_to_host_in_gbp, invoicing.xero_waiver_paid_back_to_host_in_gbp,
nullif( nullif(
coalesce(guest_payments.waiver_payments_in_gbp, 0) coalesce(guest_payments.waiver_payments_without_taxes_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0), + coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0),
0 0
) as waiver_net_fees_in_gbp, ) as waiver_net_fees_in_gbp,
guest_payments.checkin_cover_fees_in_gbp, guest_payments.checkin_cover_fees_without_taxes_in_gbp,
guest_payments.total_guest_payments_in_gbp, guest_payments.total_guest_payments_without_taxes_in_gbp,
nullif( nullif(
coalesce(guest_payments.total_guest_payments_in_gbp, 0) coalesce(guest_payments.total_guest_payments_without_taxes_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0), + coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0),
0 0
) as total_guest_revenue_in_gbp, ) as total_guest_revenue_in_gbp,
-- TOTAL REVENUE -- -- TOTAL REVENUE --
nullif( nullif(
coalesce(guest_payments.total_guest_payments_in_gbp, 0) coalesce(guest_payments.total_guest_payments_without_taxes_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0) + coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0), + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0),
@ -120,21 +121,21 @@ with
) as total_revenue_in_gbp, ) as total_revenue_in_gbp,
-- GUEST REVENUE AND PAYMENTS WEIGHTED METRICS -- -- GUEST REVENUE AND PAYMENTS WEIGHTED METRICS --
guest_payments.total_guest_payments_in_gbp / nullif( guest_payments.total_guest_payments_without_taxes_in_gbp / nullif(
guest_journeys.completed_guest_journeys, 0 guest_journeys.completed_guest_journeys, 0
) as guest_payments_per_completed_guest_journey, ) as guest_payments_per_completed_guest_journey,
guest_payments.total_guest_payments_in_gbp / nullif( guest_payments.total_guest_payments_without_taxes_in_gbp / nullif(
guest_journeys.paid_guest_journeys, 0 guest_journeys.paid_guest_journeys, 0
) as guest_payments_per_paid_guest_journey, ) as guest_payments_per_paid_guest_journey,
nullif( nullif(
coalesce(guest_payments.total_guest_payments_in_gbp, 0) coalesce(guest_payments.total_guest_payments_without_taxes_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0), + coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0),
0 0
) / nullif( ) / nullif(
guest_journeys.completed_guest_journeys, 0 guest_journeys.completed_guest_journeys, 0
) as guest_revenue_per_completed_guest_journey, ) as guest_revenue_per_completed_guest_journey,
nullif( nullif(
coalesce(guest_payments.total_guest_payments_in_gbp, 0) coalesce(guest_payments.total_guest_payments_without_taxes_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0), + coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0),
0 0
) / nullif( ) / nullif(
@ -143,14 +144,14 @@ with
-- TOTAL REVENUE WEIGHTED METRICS -- -- TOTAL REVENUE WEIGHTED METRICS --
( (
coalesce(guest_payments.total_guest_payments_in_gbp, 0) coalesce(guest_payments.total_guest_payments_without_taxes_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0) + coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
) )
/ nullif(bookings.created_bookings, 0) as total_revenue_per_created_booking, / nullif(bookings.created_bookings, 0) as total_revenue_per_created_booking,
( (
coalesce(guest_payments.total_guest_payments_in_gbp, 0) coalesce(guest_payments.total_guest_payments_without_taxes_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0) + coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
@ -158,7 +159,7 @@ with
guest_journeys.created_guest_journeys, 0 guest_journeys.created_guest_journeys, 0
) as total_revenue_per_created_guest_journey, ) as total_revenue_per_created_guest_journey,
( (
coalesce(guest_payments.total_guest_payments_in_gbp, 0) coalesce(guest_payments.total_guest_payments_without_taxes_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0) + coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
@ -166,7 +167,7 @@ with
deals.deals_booked_in_month, 0 deals.deals_booked_in_month, 0
) as total_revenue_per_deals_booked_in_month, ) as total_revenue_per_deals_booked_in_month,
( (
coalesce(guest_payments.total_guest_payments_in_gbp, 0) coalesce(guest_payments.total_guest_payments_without_taxes_in_gbp, 0)
+ coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0) + coalesce(invoicing.xero_waiver_paid_back_to_host_in_gbp, 0)
+ coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoicing.xero_apis_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0)
@ -175,8 +176,8 @@ with
) as total_revenue_per_listings_booked_in_month ) as total_revenue_per_listings_booked_in_month
from int_dates_mtd_by_dimension d from int_dates_mtd_by_dimension d
left join left join
int_core__mtd_booking_metrics bookings int_core__mtd_booking_metrics bookings
on d.date = bookings.date on d.date = bookings.date
and d.dimension = bookings.dimension and d.dimension = bookings.dimension
and d.dimension_value = bookings.dimension_value and d.dimension_value = bookings.dimension_value
@ -190,18 +191,18 @@ with
on d.date = accommodations.date on d.date = accommodations.date
and d.dimension = accommodations.dimension and d.dimension = accommodations.dimension
and d.dimension_value = accommodations.dimension_value and d.dimension_value = accommodations.dimension_value
left join left join
int_core__mtd_deal_metrics deals int_core__mtd_deal_metrics deals
on d.date = deals.date on d.date = deals.date
and d.dimension = deals.dimension and d.dimension = deals.dimension
and d.dimension_value = deals.dimension_value and d.dimension_value = deals.dimension_value
left join left join
int_core__mtd_guest_payments_metrics guest_payments int_core__mtd_guest_payments_metrics guest_payments
on d.date = guest_payments.date on d.date = guest_payments.date
and d.dimension = guest_payments.dimension and d.dimension = guest_payments.dimension
and d.dimension_value = guest_payments.dimension_value and d.dimension_value = guest_payments.dimension_value
left join left join
int_xero__mtd_invoicing_metrics invoicing int_xero__mtd_invoicing_metrics invoicing
on d.date = invoicing.date on d.date = invoicing.date
and d.dimension = invoicing.dimension and d.dimension = invoicing.dimension
and d.dimension_value = invoicing.dimension_value and d.dimension_value = invoicing.dimension_value
@ -274,12 +275,12 @@ select
{{ calculate_safe_relative_increment("xero_host_resolution_payment_count") }}, {{ calculate_safe_relative_increment("xero_host_resolution_payment_count") }},
-- GUEST REVENUE AND PAYMENTS -- -- GUEST REVENUE AND PAYMENTS --
{{ calculate_safe_relative_increment("deposit_fees_in_gbp") }}, {{ calculate_safe_relative_increment("deposit_fees_without_taxes_in_gbp") }},
{{ calculate_safe_relative_increment("waiver_payments_in_gbp") }}, {{ calculate_safe_relative_increment("waiver_payments_without_taxes_in_gbp") }},
{{ calculate_safe_relative_increment("xero_waiver_paid_back_to_host_in_gbp") }}, {{ calculate_safe_relative_increment("xero_waiver_paid_back_to_host_in_gbp") }},
{{ calculate_safe_relative_increment("waiver_net_fees_in_gbp") }}, {{ calculate_safe_relative_increment("waiver_net_fees_in_gbp") }},
{{ calculate_safe_relative_increment("checkin_cover_fees_in_gbp") }}, {{ calculate_safe_relative_increment("checkin_cover_fees_without_taxes_in_gbp") }},
{{ calculate_safe_relative_increment("total_guest_payments_in_gbp") }}, {{ calculate_safe_relative_increment("total_guest_payments_without_taxes_in_gbp") }},
{{ calculate_safe_relative_increment("total_guest_revenue_in_gbp") }}, {{ calculate_safe_relative_increment("total_guest_revenue_in_gbp") }},
-- TOTAL REVENUE -- -- TOTAL REVENUE --
@ -308,7 +309,7 @@ select
from plain_kpi_combination current from plain_kpi_combination current
left join left join
plain_kpi_combination previous_year plain_kpi_combination previous_year
on current.dimension = previous_year.dimension on current.dimension = previous_year.dimension
and current.dimension_value = previous_year.dimension_value and current.dimension_value = previous_year.dimension_value
and current.month = previous_year.month and current.month = previous_year.month
and current.year = previous_year.year + 1 and current.year = previous_year.year + 1