data-dwh-dbt-project/models/intermediate/cross/int_dates_mtd_by_dimension.sql
Oriol Roqué Paniagua 5e1b418570 Merged PR 3469: Switches Listing and Deal metrics
# Description

Switches Listings and Deal metrics to production.
I also modified the dependencies on the old lifecycles to read from the news, so we can remove these in a following PR.

I'm considering re-computing also the dimension - specific models to operate within KPIs folder, but will do this later on in a dedicated PR.

# 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: #23761
2024-11-08 11:11:04 +00:00

36 lines
1.2 KiB
SQL

{% set dimensions = get_kpi_dimensions() %}
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
with
int_kpis__dimension_daily_accommodation as (
select * from {{ ref("int_kpis__dimension_daily_accommodation") }}
),
int_core__user_host as (select * from {{ ref("int_core__user_host") }}),
int_dates_mtd as (select * from {{ ref("int_dates_mtd") }})
{% for dimension in dimensions %}
select distinct
d.year,
d.month,
d.day,
d.date,
{{ dimension.dimension }} as dimension,
{{ dimension.dimension_value }} as dimension_value,
d.first_day_month,
d.last_day_month,
d.is_end_of_month,
d.is_current_month
from int_dates_mtd d
{% if dimension.dimension == "'by_number_of_listings'" %}
inner join int_kpis__dimension_daily_accommodation a on d.date = a.date
{% elif dimension.dimension == "'by_billing_country'" %}
inner join
int_core__user_host h
on d.date >= date(h.created_date_utc)
and h.main_billing_country_iso_3_per_deal is not null
{% endif %}
{% if not loop.last %}
union all
{% endif %}
{% endfor %}