Merged PR 4946: Allows By Deal dimension to be propagated within intermediate
# Description To be able to compute By Deal KPIs similarly as we do for Main KPIs we need to propagate the "By Deal" dimension first in intermediate. This does not impact reporting since there's a macro that already cuts the dimensions to be displayed, but I modified the name so it's clearer. Changes: * In `int_mtd_vs_previous_year_metrics`, I added a new `dimension_list`. This is applied to all initial CTEs that filter by dimension. Note that I added here the `by_deal` dimension. * Modified the name of `get_kpi_dimensions_for_production` to `get_main_kpis_dimensions_for_production`. Now it's more explicit that this is the configuration for Main KPIs reporting. This affects both `business_kpis_configuration` and it's usage in `mtd_aggregated_metrics`. * Modified the tests in `int_mtd_vs_previous_year_metrics` and `int_mtd_aggregated_metrics` to include the new dimension `by_deal`. * It seems by adding this now autoformatting works again on this model! I'll tag all cases that are just because of autoformatting. MD5 trick has been applied in `reporting.mtd_aggregated_metrics`. # 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: #28998
This commit is contained in:
parent
17f38b2106
commit
ca5db795a3
4 changed files with 56 additions and 90 deletions
|
|
@ -2,104 +2,84 @@
|
|||
This model pivots the data of the different mtd metrics models to get
|
||||
previous year for each line & computing relative increment. --
|
||||
*/
|
||||
{% set dimension_list = (
|
||||
"global",
|
||||
"by_number_of_listings",
|
||||
"by_billing_country",
|
||||
"by_business_scope",
|
||||
"by_deal",
|
||||
) %}
|
||||
|
||||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
with
|
||||
created_bookings as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_created_bookings") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
union all
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_created_bookings") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
check_out_bookings as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_check_out_bookings") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
union all
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_check_out_bookings") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
billable_bookings as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_billable_bookings") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
union all
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_billable_bookings") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
created_guest_journeys as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_created_guest_journeys") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
union all
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_created_guest_journeys") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
started_guest_journeys as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_started_guest_journeys") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
union all
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_started_guest_journeys") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
completed_guest_journeys as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_completed_guest_journeys") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
union all
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_completed_guest_journeys") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
guest_journeys_with_payment as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_guest_journeys_with_payment") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
union all
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_guest_journeys_with_payment") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
listings as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_daily_listings") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
dimension in {{ dimension_list }}
|
||||
and dimension_value <> 'UNSET'
|
||||
and (is_month_to_date = true or is_end_of_month = true)
|
||||
),
|
||||
|
|
@ -107,76 +87,56 @@ with
|
|||
select *
|
||||
from {{ ref("int_kpis__agg_daily_deals") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
dimension in {{ dimension_list }}
|
||||
and dimension_value <> 'UNSET'
|
||||
and (is_month_to_date = true or is_end_of_month = true)
|
||||
),
|
||||
guest_payments as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_guest_payments") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
union all
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_guest_payments") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
invoiced_revenue as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_invoiced_revenue") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} 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', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} 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', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} 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', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
total_and_retained_revenue as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_mtd_total_and_retained_revenue") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
union all
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_total_and_retained_revenue") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
int_kpis__agg_monthly_churn_contribution as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_churn_contribution") }}
|
||||
select * from {{ ref("int_kpis__agg_monthly_churn_contribution") }}
|
||||
),
|
||||
int_kpis__agg_dates_main_kpis as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_dates_main_kpis") }}
|
||||
where
|
||||
dimension in ('global', 'by_number_of_listings', 'by_billing_country', 'by_business_scope')
|
||||
and dimension_value <> 'UNSET'
|
||||
where dimension in {{ dimension_list }} and dimension_value <> 'UNSET'
|
||||
),
|
||||
int_kpis__agg_monthly_onboarding_mrr as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_onboarding_mrr")}}
|
||||
select * from {{ ref("int_kpis__agg_monthly_onboarding_mrr") }}
|
||||
),
|
||||
plain_kpi_combination as (
|
||||
|
||||
|
|
@ -281,8 +241,7 @@ with
|
|||
as host_resolution_amount_paid_per_created_booking,
|
||||
{{
|
||||
return_capped_value(
|
||||
"cast(host_resolutions.xero_host_resolution_payment_count as decimal)
|
||||
/ created_bookings.created_bookings",
|
||||
"cast(host_resolutions.xero_host_resolution_payment_count as decimal) / created_bookings.created_bookings",
|
||||
-1,
|
||||
1,
|
||||
)
|
||||
|
|
@ -313,16 +272,16 @@ with
|
|||
) as guest_payments_per_paid_guest_journey,
|
||||
|
||||
-- TOTAL REVENUE WEIGHTED METRICS --
|
||||
coalesce(total_and_retained_revenue.total_revenue_in_gbp,0) / nullif(
|
||||
coalesce(total_and_retained_revenue.total_revenue_in_gbp, 0) / nullif(
|
||||
created_bookings.created_bookings, 0
|
||||
) as total_revenue_per_created_booking,
|
||||
coalesce(total_and_retained_revenue.total_revenue_in_gbp,0) / nullif(
|
||||
coalesce(total_and_retained_revenue.total_revenue_in_gbp, 0) / nullif(
|
||||
created_guest_journeys.created_guest_journeys, 0
|
||||
) as total_revenue_per_created_guest_journey,
|
||||
coalesce(total_and_retained_revenue.total_revenue_in_gbp,0) / nullif(
|
||||
coalesce(total_and_retained_revenue.total_revenue_in_gbp, 0) / nullif(
|
||||
deals.deals_booked_in_month, 0
|
||||
) as total_revenue_per_deals_booked_in_month,
|
||||
coalesce(total_and_retained_revenue.total_revenue_in_gbp,0) / nullif(
|
||||
coalesce(total_and_retained_revenue.total_revenue_in_gbp, 0) / nullif(
|
||||
listings.listings_booked_in_month, 0
|
||||
) as total_revenue_per_listings_booked_in_month,
|
||||
|
||||
|
|
@ -337,8 +296,7 @@ with
|
|||
total_and_retained_revenue.revenue_retained_in_gbp,
|
||||
{{
|
||||
return_capped_value(
|
||||
"total_and_retained_revenue.revenue_retained_in_gbp
|
||||
/ total_and_retained_revenue.total_revenue_in_gbp",
|
||||
"total_and_retained_revenue.revenue_retained_in_gbp / total_and_retained_revenue.total_revenue_in_gbp",
|
||||
-1,
|
||||
1,
|
||||
)
|
||||
|
|
@ -349,8 +307,7 @@ with
|
|||
total_and_retained_revenue.revenue_retained_post_resolutions_in_gbp,
|
||||
{{
|
||||
return_capped_value(
|
||||
"total_and_retained_revenue.revenue_retained_post_resolutions_in_gbp
|
||||
/ total_and_retained_revenue.total_revenue_in_gbp",
|
||||
"total_and_retained_revenue.revenue_retained_post_resolutions_in_gbp / total_and_retained_revenue.total_revenue_in_gbp",
|
||||
-1,
|
||||
1,
|
||||
)
|
||||
|
|
@ -432,7 +389,7 @@ with
|
|||
on d.date = onboarding_mrr.date
|
||||
and d.dimension = onboarding_mrr.dimension
|
||||
and d.dimension_value = onboarding_mrr.dimension_value
|
||||
left join
|
||||
left join
|
||||
total_and_retained_revenue
|
||||
on d.date = total_and_retained_revenue.end_date
|
||||
and d.dimension = total_and_retained_revenue.dimension
|
||||
|
|
@ -504,7 +461,11 @@ select
|
|||
|
||||
-- HOST (OPERATOR) REVENUE --
|
||||
-- OLD DASH --
|
||||
{{ calculate_safe_relative_increment("xero_old_dashboard_booking_net_fees_in_gbp") }},
|
||||
{{
|
||||
calculate_safe_relative_increment(
|
||||
"xero_old_dashboard_booking_net_fees_in_gbp"
|
||||
)
|
||||
}},
|
||||
{{ calculate_safe_relative_increment("xero_listing_net_fees_in_gbp") }},
|
||||
{{ calculate_safe_relative_increment("xero_verification_net_fees_in_gbp") }},
|
||||
-- NEW DASH --
|
||||
|
|
@ -604,5 +565,8 @@ left join
|
|||
where
|
||||
(
|
||||
current.is_end_of_month = true
|
||||
or (current.is_current_month = true and (current.day = previous_year.day or previous_year.day is null))
|
||||
or (
|
||||
current.is_current_month = true
|
||||
and (current.day = previous_year.day or previous_year.day is null)
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -169,6 +169,7 @@ models:
|
|||
- by_number_of_listings
|
||||
- by_billing_country
|
||||
- by_business_scope
|
||||
- by_deal
|
||||
|
||||
- name: dimension_value
|
||||
data_type: string
|
||||
|
|
@ -255,6 +256,7 @@ models:
|
|||
- by_number_of_listings
|
||||
- by_billing_country
|
||||
- by_business_scope
|
||||
- by_deal
|
||||
|
||||
- name: dimension_value
|
||||
data_type: string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue