This is a first approach to compute some easy metrics for the "deal" based business kpis. At this stage, it contains the information of bookings (created, checkout, cancelled) per deal and month, including both historic months as well as the current one. This do not contain MTD computation because it's overkill to do a MTD at deal level (+ we have 1k deals, so scalability can become a problem in the future) Models: - **int_dates_by_deal**: simple model that reads from **int_dates** and just joins it with **unified_users** to retrieve the deals. It will be used as the 'source of truth' for which deals should be considered in a given month, basically, since the first host associated to a deal is created (not necessarily booked) - **int_core__monthly_booking_history_by_deal**: it contains the history of bookings per deal id in a monthly basis. It should be easy enough to integrate here, in the future and if needed, B2B macro segmentation. In terms of performance, comparing the model **int_core__monthly_booking_history_by_deal** and **int_core__mtd_booking_metrics** you'll see that I removed the joined with the **int_dates_xxx** in the CTEs. This is because I want to avoid a double join of date & deal that I tried and I stopped after 5 min running. Since this computation is in a monthly basis - no MTD - it's easy enough to just apply the **int_dates_by_deal** on the last part of the query. With this approach, it runs in 7 seconds. Related work items: #17689
28 lines
809 B
SQL
28 lines
809 B
SQL
/*
|
|
This model provides the necessary dates for each deal for deal-based KPIs models to work.
|
|
|
|
*/
|
|
with
|
|
int_dates as (select * from {{ ref("int_dates") }}),
|
|
int_core__unified_user as (select * from {{ ref("int_core__unified_user") }})
|
|
|
|
select distinct
|
|
d.year_number as year,
|
|
d.month_of_year as month,
|
|
d.day_of_month as day,
|
|
d.date_day as date,
|
|
u.id_deal,
|
|
d.month_start_date as first_day_month,
|
|
d.month_end_date as last_day_month
|
|
from int_core__unified_user u
|
|
inner join int_dates d on d.date_day >= u.created_date_utc
|
|
where
|
|
u.id_deal is not null
|
|
-- include only up-to yesterday
|
|
and now()::date > d.date_day
|
|
and (
|
|
-- keep all last day of the month
|
|
d.date_day = d.month_end_date
|
|
-- keep yesterday
|
|
or now()::date = d.date_day + 1
|
|
)
|