Merged PR 2232: KPI refactor - 1st step, bookings

First step on refactor of kpis:
- Remove relative incremental vs. previous year computation from the source model (`mtd_booking_metrics`, in this case)
- Aggregate the source mtd global metrics models into a single model: `int_mtd_vs_previous_year_metrics` (to enable multi-source weighted metric computation) and compute previous year value and relative increment. Now this logic is encapsulated into a macro `calculate_safe_relative_increment`, easing readability and providing a bit more robustness.
- End-to-end continuity to not break the existing dashboard display in `int_core__mtd_aggregated_metrics`

This is a substep of the global change. All info can be found in the documentation [here](https://www.notion.so/knowyourguest-superhog/Refactoring-Business-KPIs-5deb6aadddb34884ae90339402ac16e3)

Related work items: #18202
This commit is contained in:
Oriol Roqué Paniagua 2024-07-08 15:58:36 +00:00
parent 62ad19ea9e
commit 409ac47591
5 changed files with 101 additions and 46 deletions

View file

@ -0,0 +1,14 @@
/*
This macro displays a metric value common in two sources, current and previous,
and computes the relative increment of current vs. previous.
It's designed to be placed within a SELECT statement.
It ensure safe divide by zero division by applying a nullif function.
*/
{% macro calculate_safe_relative_increment(metric, current='current', previous='previous_year') %}
{{ current }}.{{ metric }},
{{ previous }}.{{ metric }} as {{ previous }}_{{ metric }},
cast({{ current }}.{{ metric }} as decimal) / nullif({{ previous }}.{{ metric }},0) - 1 as relative_increment_{{ metric }}
{% endmacro %}