From 696ac24e353fb5a1c598a7b9ee2a14d02ae02479 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Thu, 30 Jan 2025 17:18:08 +0100 Subject: [PATCH] updated monthly_aggregated_metrics_history_by_deal --- macros/is_date_before_previous_month.sql | 18 ------ ...hly_aggregated_metrics_history_by_deal.sql | 56 +++++++++---------- 2 files changed, 28 insertions(+), 46 deletions(-) delete mode 100644 macros/is_date_before_previous_month.sql diff --git a/macros/is_date_before_previous_month.sql b/macros/is_date_before_previous_month.sql deleted file mode 100644 index b2ac3fa..0000000 --- a/macros/is_date_before_previous_month.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* -This macro provides a boolean answer to the question: -- Is this date before the previous month? -The computation is based on the current date by using now() - -Inputs: - - date: the date from which you want to check -Output: - - boolean; true for is before the previous month - false for is not before the previous month -*/ -{% macro is_date_before_previous_month(date) %} - ( - date_trunc('month', ({{ date }})::date)::date - + interval '1 month' - )::date - < date_trunc('month', now())::date -{% endmacro %} diff --git a/models/reporting/general/monthly_aggregated_metrics_history_by_deal.sql b/models/reporting/general/monthly_aggregated_metrics_history_by_deal.sql index 9a489f0..9b121ed 100644 --- a/models/reporting/general/monthly_aggregated_metrics_history_by_deal.sql +++ b/models/reporting/general/monthly_aggregated_metrics_history_by_deal.sql @@ -32,32 +32,32 @@ select listings_booked_in_12_months as listings_booked_in_12_months, -- Avoid displaying revenue figures until invoicing period finishes case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then total_revenue_in_gbp else null end as total_revenue_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then total_revenue_per_created_booking else null end as total_revenue_per_created_booking, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then total_revenue_per_created_guest_journey else null end as total_revenue_per_created_guest_journey, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then total_revenue_per_listings_booked_in_month else null end as total_revenue_per_listings_booked_in_month, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_operator_net_fees_in_gbp else null end as xero_operator_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_apis_net_fees_in_gbp else null end as xero_apis_net_fees_in_gbp, @@ -66,92 +66,92 @@ select as guest_revenue_per_completed_guest_journey, guest_payments_per_paid_guest_journey as guest_revenue_per_paid_guest_journey, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_host_resolution_amount_paid_in_gbp else null end as xero_host_resolution_amount_paid_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_host_resolution_payment_count else null end as xero_host_resolution_payment_count, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then host_resolution_amount_paid_per_created_booking else null end as host_resolution_amount_paid_per_created_booking, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then host_resolution_payment_per_created_booking_ratio else null end as host_resolution_payment_per_created_booking_ratio, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_booking_net_fees_in_gbp else null end as xero_booking_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_listing_net_fees_in_gbp else null end as xero_listing_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_verification_net_fees_in_gbp else null end as xero_verification_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_basic_protection_net_fees_in_gbp else null end as xero_basic_protection_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_waiver_pro_net_fees_in_gbp else null end as xero_waiver_pro_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_id_verification_net_fees_in_gbp else null end as xero_id_verification_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_protection_plus_net_fees_in_gbp else null end as xero_protection_plus_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_screening_plus_net_fees_in_gbp else null end as xero_screening_plus_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_sex_offenders_check_net_fees_in_gbp else null end as xero_sex_offenders_check_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_protection_pro_net_fees_in_gbp else null end as xero_protection_pro_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_guesty_net_fees_in_gbp else null end as xero_guesty_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_e_deposit_net_fees_in_gbp else null end as xero_e_deposit_net_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then xero_waiver_paid_back_to_host_in_gbp else null end as xero_waiver_paid_back_to_host_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then waiver_net_fees_in_gbp else null end as waiver_net_fees_in_gbp, @@ -159,22 +159,22 @@ select waiver_payments_in_gbp as waiver_payments_in_gbp, checkin_cover_fees_in_gbp as checkin_cover_fees_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then revenue_retained_in_gbp else null end as revenue_retained_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then revenue_retained_ratio else null end as revenue_retained_ratio, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then revenue_retained_post_resolutions_in_gbp else null end as revenue_retained_post_resolutions_in_gbp, case - when {{ is_date_before_previous_month("date") }} + when {{ is_date_before_20th_of_previous_month("date") }} then revenue_retained_post_resolutions_ratio else null end as revenue_retained_post_resolutions_ratio