From 55f8b47faa69121d2a24f1340c935d97248e2ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20Roqu=C3=A9=20Paniagua?= Date: Wed, 9 Apr 2025 08:13:44 +0000 Subject: [PATCH] Merged PR 4959: Exclude data from model to improve performance # Description Small changes to exclude "irrelevant" data. All data is relevant I guess but this is less. * Exclude churned accounts after 3 months. * Exclude any data after 24 months. # 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. - [ ] I have checked for DRY opportunities with other models and docs. - [ ] 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 --- .../cross/int_mtd_aggregated_metrics_by_deal.sql | 11 +++++++++++ models/intermediate/cross/schema.yml | 3 +++ models/reporting/general/schema.yml | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/models/intermediate/cross/int_mtd_aggregated_metrics_by_deal.sql b/models/intermediate/cross/int_mtd_aggregated_metrics_by_deal.sql index f255d0e..cb4c140 100644 --- a/models/intermediate/cross/int_mtd_aggregated_metrics_by_deal.sql +++ b/models/intermediate/cross/int_mtd_aggregated_metrics_by_deal.sql @@ -75,3 +75,14 @@ left join int_kpis__dimension_daily_accommodation as dda on m.date = dda.date and m.dimension_value = dda.id_deal +where + -- Only keep data for the last 24 months + m.first_day_month + interval '24 months' >= date_trunc('month', current_date) + and ( + -- Display all accounts that have not churned + hd.cancellation_date_utc is null + -- Display historical information for accounts that have churned. This includes + -- any data equal or prior to 3 months after the account has churned. + or m.first_day_month + <= date_trunc('month', hd.cancellation_date_utc) + interval '3 months' + ) diff --git a/models/intermediate/cross/schema.yml b/models/intermediate/cross/schema.yml index 5ec3411..96d5ea0 100644 --- a/models/intermediate/cross/schema.yml +++ b/models/intermediate/cross/schema.yml @@ -2616,6 +2616,9 @@ models: This model aggregates the historic information of our business by providing different metrics at account level (by id_deal). Additionally it provides Deal attributes. + Metrics displayed in the model range for the past 24 months. Also, churned + accounts are available for historical values, until 3 months after the offboarding + date. data_tests: - dbt_utils.unique_combination_of_columns: diff --git a/models/reporting/general/schema.yml b/models/reporting/general/schema.yml index 41d5447..c42aec2 100644 --- a/models/reporting/general/schema.yml +++ b/models/reporting/general/schema.yml @@ -2335,6 +2335,12 @@ models: This model aggregates the historic information of our business by providing different metrics at account level (by id_deal). Additionally it provides Deal attributes. + Metrics displayed in the model range for the past 24 months. Also, churned + accounts are available for historical values, until 3 months after the offboarding + date. + Keep in mind that metrics that depend on the invoicing cycle are only available with + a time delay. If you need timely information, at your own risk, check the equivalent + intermediate model. data_tests: - dbt_utils.unique_combination_of_columns: