diff --git a/models/intermediate/cross/int_monthly_guest_revenue_history_by_deal.sql b/models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql similarity index 100% rename from models/intermediate/cross/int_monthly_guest_revenue_history_by_deal.sql rename to models/intermediate/core/int_core__monthly_guest_payments_history_by_deal.sql diff --git a/models/intermediate/cross/int_mtd_guest_revenue_metrics.sql b/models/intermediate/core/int_core__mtd_guest_payments_metrics.sql similarity index 100% rename from models/intermediate/cross/int_mtd_guest_revenue_metrics.sql rename to models/intermediate/core/int_core__mtd_guest_payments_metrics.sql diff --git a/models/intermediate/core/schema.yaml b/models/intermediate/core/schema.yaml index 61fcb64..ec98b00 100644 --- a/models/intermediate/core/schema.yaml +++ b/models/intermediate/core/schema.yaml @@ -272,6 +272,44 @@ models: - not_null - unique + - name: int_mtd_guest_payments_metrics + description: | + This model contains the historic information regarding the guest revenue in an aggregated manner. + It's used for the business KPIs. Data is aggregated at the last day of the month and in the + days necessary for the Month-to-Date computation of the current month. + + columns: + - name: date + data_type: date + description: The date for the month-to-date guest revenue-related metrics. + tests: + - not_null + - unique + + - name: int_monthly_guest_payments_history_by_deal + description: | + This model contains the historic information regarding the guest revenue for each deal id. + It's used for the business KPIs in the view by deal id. Data is aggregated at the last + day of the month, or up to yesterday if it's the current month. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - date + - id_deal + + columns: + - name: date + data_type: date + description: The last day of the month or yesterday for historic guest revenue metrics. + tests: + - not_null + + - name: id_deal + data_type: character varying + description: Id of the deal associated to the host. + tests: + - not_null + - name: int_core__verification_request_completeness description: | The `int_core__verification_request_completeness` model allows to determine if a verification request is diff --git a/models/intermediate/cross/int_monthly_aggregated_metrics_history_by_deal.sql b/models/intermediate/cross/int_monthly_aggregated_metrics_history_by_deal.sql index c8773c0..1d7ab43 100644 --- a/models/intermediate/cross/int_monthly_aggregated_metrics_history_by_deal.sql +++ b/models/intermediate/cross/int_monthly_aggregated_metrics_history_by_deal.sql @@ -19,8 +19,8 @@ with int_xero__monthly_invoicing_history_by_deal as ( select * from {{ ref("int_xero__monthly_invoicing_history_by_deal") }} ), - int_monthly_guest_revenue_history_by_deal as ( - select * from {{ ref("int_monthly_guest_revenue_history_by_deal") }} + int_core__monthly_guest_payments_history_by_deal as ( + select * from {{ ref("int_core__monthly_guest_payments_history_by_deal") }} ) select @@ -77,20 +77,20 @@ select invoicing.xero_host_resolution_payment_count, -- GUEST REVENUE AND PAYMENTS -- - guest_revenue.deposit_fees_in_gbp, - guest_revenue.waiver_payments_in_gbp, - guest_revenue.checkin_cover_fees_in_gbp, - guest_revenue.total_guest_payments_in_gbp, - guest_revenue.total_guest_income_in_gbp, + guest_payments.deposit_fees_in_gbp, + guest_payments.waiver_payments_in_gbp, + guest_payments.checkin_cover_fees_in_gbp, + guest_payments.total_guest_payments_in_gbp, + guest_payments.total_guest_income_in_gbp, nullif( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0), 0 ) as total_guest_revenue_in_gbp, -- TOTAL REVENUE -- nullif( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0), @@ -98,21 +98,21 @@ select ) as total_revenue_in_gbp, -- GUEST REVENUE AND PAYMENTS WEIGHTED METRICS -- - guest_revenue.total_guest_payments_in_gbp / nullif( + guest_payments.total_guest_payments_in_gbp / nullif( guest_journeys.completed_guest_journeys, 0 ) as guest_payments_per_completed_guest_journey, - guest_revenue.total_guest_payments_in_gbp / nullif( + guest_payments.total_guest_payments_in_gbp / nullif( guest_journeys.paid_guest_journeys, 0 ) as guest_payments_per_paid_guest_journey, nullif( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0), 0 ) / nullif( guest_journeys.completed_guest_journeys, 0 ) as guest_revenue_per_completed_guest_journey, nullif( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0), 0 ) / nullif( @@ -121,14 +121,14 @@ select -- TOTAL REVENUE WEIGHTED METRICS -- ( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_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, ( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0) @@ -136,7 +136,7 @@ select guest_journeys.created_guest_journeys, 0 ) as total_revenue_per_created_guest_journey, ( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0) @@ -162,9 +162,9 @@ left join on d.date = accommodations.date and d.id_deal = accommodations.id_deal left join - int_monthly_guest_revenue_history_by_deal guest_revenue - on d.date = guest_revenue.date - and d.id_deal = guest_revenue.id_deal + int_core__monthly_guest_payments_history_by_deal guest_payments + on d.date = guest_payments.date + and d.id_deal = guest_payments.id_deal left join int_xero__monthly_invoicing_history_by_deal invoicing on d.date = invoicing.date diff --git a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql index 6b42fb6..2c80fce 100644 --- a/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql +++ b/models/intermediate/cross/int_mtd_vs_previous_year_metrics.sql @@ -16,8 +16,8 @@ with int_core__mtd_deal_metrics as ( select * from {{ ref("int_core__mtd_deal_metrics") }} ), - int_mtd_guest_revenue_metrics as ( - select * from {{ ref("int_mtd_guest_revenue_metrics") }} + int_core__mtd_guest_payments_metrics as ( + select * from {{ ref("int_core__mtd_guest_payments_metrics") }} ), int_xero__mtd_invoicing_metrics as ( select * from {{ ref("int_xero__mtd_invoicing_metrics") }} @@ -92,20 +92,20 @@ with invoicing.xero_host_resolution_payment_count, -- GUEST REVENUE AND PAYMENTS -- - guest_revenue.deposit_fees_in_gbp, - guest_revenue.waiver_payments_in_gbp, - guest_revenue.checkin_cover_fees_in_gbp, - guest_revenue.total_guest_payments_in_gbp, - guest_revenue.total_guest_income_in_gbp, + guest_payments.deposit_fees_in_gbp, + guest_payments.waiver_payments_in_gbp, + guest_payments.checkin_cover_fees_in_gbp, + guest_payments.total_guest_payments_in_gbp, + guest_payments.total_guest_income_in_gbp, nullif( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0), 0 ) as total_guest_revenue_in_gbp, -- TOTAL REVENUE -- nullif( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0), @@ -113,21 +113,21 @@ with ) as total_revenue_in_gbp, -- GUEST REVENUE AND PAYMENTS WEIGHTED METRICS -- - guest_revenue.total_guest_payments_in_gbp / nullif( + guest_payments.total_guest_payments_in_gbp / nullif( guest_journeys.completed_guest_journeys, 0 ) as guest_payments_per_completed_guest_journey, - guest_revenue.total_guest_payments_in_gbp / nullif( + guest_payments.total_guest_payments_in_gbp / nullif( guest_journeys.paid_guest_journeys, 0 ) as guest_payments_per_paid_guest_journey, nullif( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0), 0 ) / nullif( guest_journeys.completed_guest_journeys, 0 ) as guest_revenue_per_completed_guest_journey, nullif( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0), 0 ) / nullif( @@ -136,14 +136,14 @@ with -- TOTAL REVENUE WEIGHTED METRICS -- ( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_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, ( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0) @@ -151,7 +151,7 @@ with guest_journeys.created_guest_journeys, 0 ) as total_revenue_per_created_guest_journey, ( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0) @@ -159,7 +159,7 @@ with deals.deals_booked_in_month, 0 ) as total_revenue_per_deals_booked_in_month, ( - coalesce(guest_revenue.total_guest_income_in_gbp, 0) + coalesce(guest_payments.total_guest_income_in_gbp, 0) + coalesce(invoicing.xero_waiver_net_fees_in_gbp, 0) + coalesce(invoicing.xero_operator_net_fees_in_gbp, 0) + coalesce(invoicing.xero_apis_net_fees_in_gbp, 0) @@ -177,7 +177,7 @@ with on d.date = accommodations.date left join int_core__mtd_deal_metrics deals on d.date = deals.date left join - int_mtd_guest_revenue_metrics guest_revenue on d.date = guest_revenue.date + int_core__mtd_guest_payments_metrics guest_payments on d.date = guest_payments.date left join int_xero__mtd_invoicing_metrics invoicing on d.date = invoicing.date ) select diff --git a/models/intermediate/cross/schema.yml b/models/intermediate/cross/schema.yml index 548d904..5858491 100644 --- a/models/intermediate/cross/schema.yml +++ b/models/intermediate/cross/schema.yml @@ -132,20 +132,6 @@ models: tests: - not_null - - name: int_mtd_guest_revenue_metrics - description: | - This model contains the historic information regarding the guest revenue in an aggregated manner. - It's used for the business KPIs. Data is aggregated at the last day of the month and in the - days necessary for the Month-to-Date computation of the current month. - - columns: - - name: date - data_type: date - description: The date for the month-to-date guest revenue-related metrics. - tests: - - not_null - - unique - - name: int_mtd_vs_previous_year_metrics description: | This model is used for global KPIs. @@ -164,30 +150,6 @@ models: - not_null - unique - - name: int_monthly_guest_revenue_history_by_deal - description: | - This model contains the historic information regarding the guest revenue for each deal id. - It's used for the business KPIs in the view by deal id. Data is aggregated at the last - day of the month, or up to yesterday if it's the current month. - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - date - - id_deal - - columns: - - name: date - data_type: date - description: The last day of the month or yesterday for historic guest revenue metrics. - tests: - - not_null - - - name: id_deal - data_type: character varying - description: Id of the deal associated to the host. - tests: - - not_null - - name: int_mtd_aggregated_metrics description: | The `int_mtd_aggregated_metrics` model aggregates multiple metrics on a year, month, and day basis.