Fixed model aggregations

This commit is contained in:
Joaquin 2025-04-01 14:24:14 +02:00
parent 2a797ce0e8
commit 264ce4e203
4 changed files with 16 additions and 74 deletions

View file

@ -6,13 +6,17 @@
{% for dimension in dimensions %} {% for dimension in dimensions %}
select select
-- Unique Key -- -- Unique Key --
start_date, d.first_day_month as start_date,
end_date, d.date as end_date,
{{ dimension.dimension }} as dimension, {{ dimension.dimension }} as dimension,
{{ dimension.dimension_value }} as dimension_value, {{ dimension.dimension_value }} as dimension_value,
-- Metrics -- -- Metrics --
sum(created_bookings) as created_bookings count(distinct dcb.id_booking) as created_bookings
from {{ ref("int_kpis__metric_monthly_new_dash_created_bookings") }} from {{ ref("int_kpis__dimension_dates") }} d
left join
{{ ref("int_kpis__metric_daily_new_dash_created_bookings") }} as dcb
on dcb.date = d.date
where d.is_end_of_month = true and dcb.id_booking is not null
group by 1, 2, 3, 4 group by 1, 2, 3, 4
{% if not loop.last %} {% if not loop.last %}
union all union all

View file

@ -6,13 +6,17 @@
{% for dimension in dimensions %} {% for dimension in dimensions %}
select select
-- Unique Key -- -- Unique Key --
start_date, d.first_day_month as start_date,
end_date, d.date as end_date,
{{ dimension.dimension }} as dimension, {{ dimension.dimension }} as dimension,
{{ dimension.dimension_value }} as dimension_value, {{ dimension.dimension_value }} as dimension_value,
-- Metrics -- -- Metrics --
sum(created_bookings) as created_bookings count(distinct dcb.id_booking) as created_bookings
from {{ ref("int_kpis__metric_weekly_new_dash_created_bookings") }} from {{ ref("int_kpis__dimension_dates") }} d
left join
{{ ref("int_kpis__metric_daily_new_dash_created_bookings") }} as dcb
on dcb.date = d.date
where d.is_end_of_week = true and dcb.id_booking is not null
group by 1, 2, 3, 4 group by 1, 2, 3, 4
{% if not loop.last %} {% if not loop.last %}
union all union all

View file

@ -1,33 +0,0 @@
{{
config(
materialized="view",
unique_key=[
"end_date",
"service_name",
"id_deal",
"active_accommodations_per_deal_segmentation",
"service_business_type",
],
)
}}
select
-- Unique Key --
d.first_day_month as start_date,
d.date as end_date,
cbs.service_name,
cbs.active_accommodations_per_deal_segmentation,
cbs.id_deal,
cbs.service_business_type,
-- Dimensions --
cbs.new_dash_version,
cbs.is_upgraded_service,
cbs.main_billing_country_iso_3_per_deal,
-- Metrics --
count(distinct cbs.id_booking) as created_bookings
from {{ ref("int_kpis__dimension_dates") }} d
left join
{{ ref("int_kpis__metric_daily_new_dash_created_bookings") }} cbs
on date_trunc('month', cbs.date)::date = d.first_day_month
where d.is_end_of_month = true and cbs.id_deal is not null
group by 1, 2, 3, 4, 5, 6, 7, 8, 9

View file

@ -1,33 +0,0 @@
{{
config(
materialized="view",
unique_key=[
"end_date",
"service_name",
"id_deal",
"active_accommodations_per_deal_segmentation",
"service_business_type",
],
)
}}
select
-- Unique Key --
d.first_day_week as start_date,
d.date as end_date,
cbs.service_name,
cbs.active_accommodations_per_deal_segmentation,
cbs.id_deal,
cbs.service_business_type,
-- Dimensions --
cbs.new_dash_version,
cbs.is_upgraded_service,
cbs.main_billing_country_iso_3_per_deal,
-- Metrics --
count(distinct cbs.id_booking) as created_bookings
from {{ ref("int_kpis__dimension_dates") }} d
left join
{{ ref("int_kpis__metric_daily_new_dash_created_bookings") }} cbs
on date_trunc('week', cbs.date)::date = d.first_day_week
where d.is_end_of_week = true and cbs.id_deal is not null
group by 1, 2, 3, 4, 5, 6, 7, 8, 9