Merged PR 4970: Fix data quality issue on Revenue Retained metrics

# Description

As raised by Kayla, Retained metrics are not computed correctly in AM Account Margin report, see screenshot:

![image.png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/4970/attachments/image.png)

Issue lies in the fact that Guest Payments contains more dimensions than the rest of the models. This is generating duplicates in the combination_of_sources CTE, but these are effectively hidden because of the sum() applied of the metrics.

In the case of a Deal having in the same day Guest Payments with different dimensions from those selected, AND on the same day having a value on Invoiced Revenue or Host Resolutions, then the Invoiced Revenue or Host Resolutions would be duplicated.

This PR aims to fix this issue, and also adds a few tests on the base model for AM Account Margin to ensure this is kind of error raises an alert.

I'll be debugging other affected models and increase the robustness test-wise; as well as gathering the full impact.

# 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: #29227
This commit is contained in:
Oriol Roqué Paniagua 2025-04-10 07:23:31 +00:00
parent e5a4187e57
commit fa6114b2af
2 changed files with 73 additions and 18 deletions

View file

@ -1343,6 +1343,22 @@ models:
- id_deal
- time_window
- dbt_expectations.expect_column_pair_values_to_be_equal:
column_A: total_revenue_in_gbp
column_B: invoiced_revenue_in_gbp + guest_payments_in_gbp
- dbt_expectations.expect_column_pair_values_to_be_equal:
column_A: revenue_retained_in_gbp
column_B: total_revenue_in_gbp + waiver_paid_back_to_host_in_gbp
- dbt_expectations.expect_column_pair_values_to_be_equal:
column_A: revenue_retained_post_resolutions_in_gbp
column_B: revenue_retained_in_gbp + host_resolution_amount_paid_in_gbp
- dbt_expectations.expect_column_pair_values_to_be_equal:
column_A: guest_revenue_retained_in_gbp
column_B: guest_payments_in_gbp + waiver_paid_back_to_host_in_gbp
columns:
- name: date
data_type: date