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:
parent
62ad19ea9e
commit
409ac47591
5 changed files with 101 additions and 46 deletions
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
This model pivots the data of the different mtd metrics models to get
|
||||
previous year for each line & computing relative increment. --
|
||||
*/
|
||||
|
||||
{{ config(materialized="table", unique_key="date") }}
|
||||
with
|
||||
int_core__mtd_booking_metrics as (
|
||||
select * from {{ ref("int_core__mtd_booking_metrics") }}
|
||||
),
|
||||
int_dates_mtd as (select * from {{ ref("int_dates_mtd") }}),
|
||||
|
||||
plain_kpi_combination as (
|
||||
select
|
||||
d.year,
|
||||
d.month,
|
||||
d.day,
|
||||
d.is_end_of_month,
|
||||
d.is_current_month,
|
||||
d.date,
|
||||
bookings.created_bookings,
|
||||
bookings.check_out_bookings,
|
||||
bookings.cancelled_bookings
|
||||
from int_dates_mtd d
|
||||
left join int_core__mtd_booking_metrics bookings
|
||||
on d.date = bookings.date
|
||||
)
|
||||
select
|
||||
current.year,
|
||||
current.month,
|
||||
current.day,
|
||||
current.is_end_of_month,
|
||||
current.is_current_month,
|
||||
current.date,
|
||||
previous_year.date as previous_year_date,
|
||||
|
||||
-- BOOKINGS --
|
||||
{{ calculate_safe_relative_increment('created_bookings') }},
|
||||
{{ calculate_safe_relative_increment('check_out_bookings') }},
|
||||
{{ calculate_safe_relative_increment('cancelled_bookings') }}
|
||||
|
||||
from plain_kpi_combination current
|
||||
left join plain_kpi_combination previous_year
|
||||
on current.month = previous_year.month
|
||||
and current.year = previous_year.year + 1
|
||||
where
|
||||
(
|
||||
current.is_end_of_month = 1
|
||||
or (current.is_current_month = 1 and current.day = previous_year.day)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue