{% set dimensions = get_kpi_dimensions() %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} with int_core__mtd_accommodation_segmentation as ( select * from {{ ref("int_core__mtd_accommodation_segmentation") }} ), 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_core__mtd_accommodation_segmentation a on d.date = a.date {% elif dimension.dimension == "'by_billing_country'" %} inner join int_core__user_host h on d.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 %}