From 60dfae5cf466b707a3bd7f2e30e956fef074bde1 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 1 Apr 2025 19:51:30 +0200 Subject: [PATCH] Addressed comments --- macros/business_kpis_configuration.sql | 29 +- macros/generate_kpis_aggregation.sql | 23 ++ ...ew_dash_accommodation_offered_services.sql | 4 +- ...agg_daily_new_dash_chargeable_services.sql | 2 +- ...s__agg_daily_new_dash_created_bookings.sql | 2 +- ...s__agg_daily_new_dash_created_services.sql | 2 +- ...ew_dash_accommodation_offered_services.sql | 4 +- ...g_monthly_new_dash_chargeable_services.sql | 2 +- ..._agg_monthly_new_dash_created_bookings.sql | 2 +- ..._agg_monthly_new_dash_created_services.sql | 2 +- ...ew_dash_accommodation_offered_services.sql | 4 +- ...gg_weekly_new_dash_chargeable_services.sql | 2 +- ...__agg_weekly_new_dash_created_bookings.sql | 2 +- ...__agg_weekly_new_dash_created_services.sql | 2 +- ...metric_daily_new_dash_created_bookings.sql | 2 +- ...int_kpis__product_new_dash_agg_metrics.sql | 299 +++++++----------- 16 files changed, 147 insertions(+), 236 deletions(-) create mode 100644 macros/generate_kpis_aggregation.sql diff --git a/macros/business_kpis_configuration.sql b/macros/business_kpis_configuration.sql index 6d0ef66..321559c 100644 --- a/macros/business_kpis_configuration.sql +++ b/macros/business_kpis_configuration.sql @@ -171,16 +171,7 @@ Provides a general assignement for the Dimensions available for each KPI ] %} {% endif %} - {% if entity_name == "NEW_DASH_CREATED_SERVICES" %} - {% set additional_dimensions = additional_dimensions + [ - dim_has_upgraded_service(), - dim_new_dash_version(), - dim_pricing_service(), - dim_pricing_business_type(), - ] %} - {% endif %} - - {% if entity_name == "NEW_DASH_CHARGEABLE_SERVICES" %} + {% if entity_name == "NEW_DASH" %} {% set additional_dimensions = additional_dimensions + [ dim_has_upgraded_service(), dim_new_dash_version(), @@ -198,24 +189,6 @@ Provides a general assignement for the Dimensions available for each KPI ] %} {% endif %} - {% if entity_name == "NEW_DASH_ACCOMMODATION_OFFERED_SERVICES" %} - {% set additional_dimensions = additional_dimensions + [ - dim_has_upgraded_service(), - dim_new_dash_version(), - dim_pricing_service(), - dim_pricing_business_type(), - ] %} - {% endif %} - - {% if entity_name == "NEW_DASH_CREATED_BOOKINGS" %} - {% set additional_dimensions = additional_dimensions + [ - dim_has_upgraded_service(), - dim_new_dash_version(), - dim_pricing_service(), - dim_pricing_business_type(), - ] %} - {% endif %} - {# Combine base dimensions with additional dimensions for the specific model #} {% set dimensions = base_dimensions + additional_dimensions %} {{ return(dimensions) }} diff --git a/macros/generate_kpis_aggregation.sql b/macros/generate_kpis_aggregation.sql new file mode 100644 index 0000000..5ce9bbc --- /dev/null +++ b/macros/generate_kpis_aggregation.sql @@ -0,0 +1,23 @@ +{% macro generate_kpis_aggregation(time_granularity, agg_models) %} + select + d.date, + '{{ time_granularity }}' as time_granularity, + d.dimension, + d.dimension_value + {%- for agg_model in agg_models if time_granularity in agg_model["name"] %} + {%- for metric in agg_model["metrics"] %} + , coalesce({{ ref(agg_model["name"]) }}.{{ metric }}, 0) as {{ metric }} + {%- endfor %} + {%- endfor %} + from all_dates d + {%- for agg_model in agg_models if time_granularity in agg_model["name"] %} + left join + {{ ref(agg_model["name"]) }} + on d.date = {{ ref(agg_model["name"]) }}.{{ agg_model["date_field"] }} + and d.dimension = {{ ref(agg_model["name"]) }}.dimension + and d.dimension_value = {{ ref(agg_model["name"]) }}.dimension_value + {%- endfor %} + {% if time_granularity == "weekly" %} where d.is_end_of_week + {% elif time_granularity == "monthly" %} where d.is_end_of_month + {% endif %} +{% endmacro %} diff --git a/models/intermediate/kpis/int_kpis__agg_daily_new_dash_accommodation_offered_services.sql b/models/intermediate/kpis/int_kpis__agg_daily_new_dash_accommodation_offered_services.sql index 080395d..3c00223 100644 --- a/models/intermediate/kpis/int_kpis__agg_daily_new_dash_accommodation_offered_services.sql +++ b/models/intermediate/kpis/int_kpis__agg_daily_new_dash_accommodation_offered_services.sql @@ -1,6 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model( - "NEW_DASH_ACCOMMODATION_OFFERED_SERVICES" -) %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} diff --git a/models/intermediate/kpis/int_kpis__agg_daily_new_dash_chargeable_services.sql b/models/intermediate/kpis/int_kpis__agg_daily_new_dash_chargeable_services.sql index 2b66697..7802dc3 100644 --- a/models/intermediate/kpis/int_kpis__agg_daily_new_dash_chargeable_services.sql +++ b/models/intermediate/kpis/int_kpis__agg_daily_new_dash_chargeable_services.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CHARGEABLE_SERVICES") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} diff --git a/models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_bookings.sql b/models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_bookings.sql index 77dd889..4fae871 100644 --- a/models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_bookings.sql +++ b/models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_bookings.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} diff --git a/models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_services.sql b/models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_services.sql index 2b1ac06..f3f74c2 100644 --- a/models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_services.sql +++ b/models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_services.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_SERVICES") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} diff --git a/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_accommodation_offered_services.sql b/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_accommodation_offered_services.sql index 7d82a9c..64ce35e 100644 --- a/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_accommodation_offered_services.sql +++ b/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_accommodation_offered_services.sql @@ -1,6 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model( - "NEW_DASH_ACCOMMODATION_OFFERED_SERVICES" -) %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} diff --git a/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_chargeable_services.sql b/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_chargeable_services.sql index f28c863..ab73cb5 100644 --- a/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_chargeable_services.sql +++ b/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_chargeable_services.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CHARGEABLE_SERVICES") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config( diff --git a/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_bookings.sql b/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_bookings.sql index 185c844..9239d5c 100644 --- a/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_bookings.sql +++ b/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_bookings.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} diff --git a/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_services.sql b/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_services.sql index 0525434..931c761 100644 --- a/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_services.sql +++ b/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_services.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_SERVICES") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config( diff --git a/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_accommodation_offered_services.sql b/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_accommodation_offered_services.sql index a353a74..97d8129 100644 --- a/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_accommodation_offered_services.sql +++ b/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_accommodation_offered_services.sql @@ -1,6 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model( - "NEW_DASH_ACCOMMODATION_OFFERED_SERVICES" -) %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} diff --git a/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_chargeable_services.sql b/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_chargeable_services.sql index 243a6be..f061305 100644 --- a/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_chargeable_services.sql +++ b/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_chargeable_services.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CHARGEABLE_SERVICES") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config( diff --git a/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_bookings.sql b/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_bookings.sql index 5bf664a..488c312 100644 --- a/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_bookings.sql +++ b/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_bookings.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} diff --git a/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_services.sql b/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_services.sql index eeb5de1..b27b261 100644 --- a/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_services.sql +++ b/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_services.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_SERVICES") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} {{ config( diff --git a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings.sql b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings.sql index 132d451..9d332d7 100644 --- a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings.sql +++ b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings.sql @@ -3,7 +3,7 @@ materialized="table", unique_key=[ "date", - "id_deal", + "id_booking", "id_user_product_bundle", "service_name", "service_business_type", diff --git a/models/intermediate/kpis/int_kpis__product_new_dash_agg_metrics.sql b/models/intermediate/kpis/int_kpis__product_new_dash_agg_metrics.sql index 0208e83..3efa1a3 100644 --- a/models/intermediate/kpis/int_kpis__product_new_dash_agg_metrics.sql +++ b/models/intermediate/kpis/int_kpis__product_new_dash_agg_metrics.sql @@ -1,208 +1,129 @@ +{% set agg_models = [ + { + "name": "int_kpis__agg_daily_new_dash_created_services", + "date_field": "date", + "metrics": ["created_services"], + }, + { + "name": "int_kpis__agg_daily_new_dash_chargeable_services", + "date_field": "date", + "metrics": [ + "total_chargeable_services", + "total_chargeable_amount_in_gbp", + "unique_chargeable_bookings", + "unique_chargeable_listings", + ], + }, + { + "name": "int_kpis__agg_daily_new_dash_deals_offered_services", + "date_field": "date", + "metrics": ["deal_with_offered_service_count"], + }, + { + "name": "int_kpis__agg_daily_new_dash_accommodation_offered_services", + "date_field": "date", + "metrics": ["accommodation_with_offered_service_count"], + }, + { + "name": "int_kpis__agg_daily_new_dash_created_bookings", + "date_field": "date", + "metrics": ["created_bookings"], + }, + { + "name": "int_kpis__agg_weekly_new_dash_created_services", + "date_field": "end_date", + "metrics": ["created_services"], + }, + { + "name": "int_kpis__agg_weekly_new_dash_chargeable_services", + "date_field": "end_date", + "metrics": [ + "total_chargeable_services", + "total_chargeable_amount_in_gbp", + "unique_chargeable_bookings", + "unique_chargeable_listings", + ], + }, + { + "name": "int_kpis__agg_weekly_new_dash_deals_offered_services", + "date_field": "date", + "metrics": ["deal_with_offered_service_count"], + }, + { + "name": "int_kpis__agg_weekly_new_dash_accommodation_offered_services", + "date_field": "date", + "metrics": ["accommodation_with_offered_service_count"], + }, + { + "name": "int_kpis__agg_weekly_new_dash_created_bookings", + "date_field": "end_date", + "metrics": ["created_bookings"], + }, + { + "name": "int_kpis__agg_monthly_new_dash_created_services", + "date_field": "end_date", + "metrics": ["created_services"], + }, + { + "name": "int_kpis__agg_monthly_new_dash_chargeable_services", + "date_field": "end_date", + "metrics": [ + "total_chargeable_services", + "total_chargeable_amount_in_gbp", + "unique_chargeable_bookings", + "unique_chargeable_listings", + ], + }, + { + "name": "int_kpis__agg_monthly_new_dash_deals_offered_services", + "date_field": "date", + "metrics": ["deal_with_offered_service_count"], + }, + { + "name": "int_kpis__agg_monthly_new_dash_accommodation_offered_services", + "date_field": "date", + "metrics": ["accommodation_with_offered_service_count"], + }, + { + "name": "int_kpis__agg_monthly_new_dash_created_bookings", + "date_field": "end_date", + "metrics": ["created_bookings"], + }, +] %} + with - int_kpis__agg_daily_new_dash_created_services as ( - select * from {{ ref("int_kpis__agg_daily_new_dash_created_services") }} - ), - int_kpis__agg_weekly_new_dash_created_services as ( - select * from {{ ref("int_kpis__agg_weekly_new_dash_created_services") }} - ), - int_kpis__agg_monthly_new_dash_created_services as ( - select * from {{ ref("int_kpis__agg_monthly_new_dash_created_services") }} - ), - int_kpis__agg_daily_new_dash_chargeable_services as ( - select * from {{ ref("int_kpis__agg_daily_new_dash_chargeable_services") }} - ), - int_kpis__agg_weekly_new_dash_chargeable_services as ( - select * from {{ ref("int_kpis__agg_weekly_new_dash_chargeable_services") }} - ), - int_kpis__agg_monthly_new_dash_chargeable_services as ( - select * from {{ ref("int_kpis__agg_monthly_new_dash_chargeable_services") }} - ), - int_kpis__agg_daily_new_dash_deals_offered_services as ( - select * from {{ ref("int_kpis__agg_daily_new_dash_deals_offered_services") }} - ), - int_kpis__agg_weekly_new_dash_deals_offered_services as ( - select * from {{ ref("int_kpis__agg_weekly_new_dash_deals_offered_services") }} - ), - int_kpis__agg_monthly_new_dash_deals_offered_services as ( - select * from {{ ref("int_kpis__agg_monthly_new_dash_deals_offered_services") }} - ), - int_kpis__agg_daily_new_dash_accommodation_offered_services as ( - select * - from {{ ref("int_kpis__agg_daily_new_dash_accommodation_offered_services") }} - ), - int_kpis__agg_weekly_new_dash_accommodation_offered_services as ( - select * - from {{ ref("int_kpis__agg_weekly_new_dash_accommodation_offered_services") }} - ), - int_kpis__agg_monthly_new_dash_accommodation_offered_services as ( - select * - from {{ ref("int_kpis__agg_monthly_new_dash_accommodation_offered_services") }} - ), - int_kpis__agg_daily_new_dash_created_bookings as ( - select * from {{ ref("int_kpis__agg_daily_new_dash_created_bookings") }} - ), - int_kpis__agg_weekly_new_dash_created_bookings as ( - select * from {{ ref("int_kpis__agg_weekly_new_dash_created_bookings") }} - ), - int_kpis__agg_monthly_new_dash_created_bookings as ( - select * from {{ ref("int_kpis__agg_monthly_new_dash_created_bookings") }} - ), int_kpis__dimension_dates as (select * from {{ ref("int_kpis__dimension_dates") }}), + all_dates as ( select distinct c.date, c.dimension, c.dimension_value, d.is_end_of_week, d.is_end_of_month from ( select date, dimension, dimension_value - from int_kpis__agg_daily_new_dash_created_services + from {{ ref("int_kpis__agg_daily_new_dash_created_services") }} union all select date, dimension, dimension_value - from int_kpis__agg_daily_new_dash_chargeable_services + from {{ ref("int_kpis__agg_daily_new_dash_chargeable_services") }} union all select date, dimension, dimension_value - from int_kpis__agg_daily_new_dash_deals_offered_services + from {{ ref("int_kpis__agg_daily_new_dash_deals_offered_services") }} union all select date, dimension, dimension_value - from int_kpis__agg_daily_new_dash_accommodation_offered_services + from + {{ + ref( + "int_kpis__agg_daily_new_dash_accommodation_offered_services" + ) + }} ) c left join int_kpis__dimension_dates d on c.date = d.date ) -select - d.date, - 'daily' as time_granularity, - d.dimension, - d.dimension_value, - coalesce( - deals.deal_with_offered_service_count, 0 - ) as deal_with_offered_service_count, - coalesce( - accommodation.accommodation_with_offered_service_count, 0 - ) as accommodation_with_offered_service_count, - coalesce(created.created_services, 0) as created_services, - coalesce(bookings.created_bookings, 0) as created_bookings_count, - coalesce(chargeable.total_chargeable_services, 0) as total_chargeable_services, - coalesce( - chargeable.total_chargeable_amount_in_gbp, 0 - ) as total_chargeable_amount_in_gbp, - coalesce(chargeable.unique_chargeable_bookings, 0) as unique_chargeable_bookings, - coalesce(chargeable.unique_chargeable_listings, 0) as unique_chargeable_listings -from all_dates d -left join - int_kpis__agg_daily_new_dash_created_services created - on d.date = created.date - and d.dimension = created.dimension - and d.dimension_value = created.dimension_value -left join - int_kpis__agg_daily_new_dash_chargeable_services chargeable - on d.date = chargeable.date - and d.dimension = chargeable.dimension - and d.dimension_value = chargeable.dimension_value -left join - int_kpis__agg_daily_new_dash_deals_offered_services deals - on d.date = deals.date - and d.dimension = deals.dimension - and d.dimension_value = deals.dimension_value -left join - int_kpis__agg_daily_new_dash_accommodation_offered_services accommodation - on d.date = accommodation.date - and d.dimension = accommodation.dimension - and d.dimension_value = accommodation.dimension_value -left join - int_kpis__agg_daily_new_dash_created_bookings bookings - on d.date = bookings.date - and d.dimension = bookings.dimension - and d.dimension_value = bookings.dimension_value + +select * +from ({{ generate_kpis_aggregation("daily", agg_models) }}) union all -select - d.date, - 'weekly' as time_granularity, - d.dimension, - d.dimension_value, - coalesce( - deals.deal_with_offered_service_count, 0 - ) as deal_with_offered_service_count, - coalesce( - accommodation.accommodation_with_offered_service_count, 0 - ) as accommodation_with_offered_service_count, - coalesce(created.created_services, 0) as created_services, - coalesce(bookings.created_bookings, 0) as created_bookings_count, - coalesce(chargeable.total_chargeable_services, 0) as total_chargeable_services, - coalesce( - chargeable.total_chargeable_amount_in_gbp, 0 - ) as total_chargeable_amount_in_gbp, - coalesce(chargeable.unique_chargeable_bookings, 0) as unique_chargeable_bookings, - coalesce(chargeable.unique_chargeable_listings, 0) as unique_chargeable_listings -from all_dates d -left join - int_kpis__agg_weekly_new_dash_created_services created - on d.date = created.end_date - and d.dimension = created.dimension - and d.dimension_value = created.dimension_value -left join - int_kpis__agg_weekly_new_dash_chargeable_services chargeable - on d.date = chargeable.end_date - and d.dimension = chargeable.dimension - and d.dimension_value = chargeable.dimension_value -left join - int_kpis__agg_weekly_new_dash_deals_offered_services deals - on d.date = deals.date - and d.dimension = deals.dimension - and d.dimension_value = deals.dimension_value -left join - int_kpis__agg_weekly_new_dash_accommodation_offered_services accommodation - on d.date = accommodation.date - and d.dimension = accommodation.dimension - and d.dimension_value = accommodation.dimension_value -left join - int_kpis__agg_weekly_new_dash_created_bookings bookings - on d.date = bookings.end_date - and d.dimension = bookings.dimension - and d.dimension_value = bookings.dimension_value -where d.is_end_of_week +select * +from ({{ generate_kpis_aggregation("weekly", agg_models) }}) union all -select - d.date, - 'monthly' as time_granularity, - d.dimension, - d.dimension_value, - coalesce( - deals.deal_with_offered_service_count, 0 - ) as deal_with_offered_service_count, - coalesce( - accommodation.accommodation_with_offered_service_count, 0 - ) as accommodation_with_offered_service_count, - coalesce(created.created_services, 0) as created_services, - coalesce(bookings.created_bookings, 0) as created_bookings_count, - coalesce(chargeable.total_chargeable_services, 0) as total_chargeable_services, - coalesce( - chargeable.total_chargeable_amount_in_gbp, 0 - ) as total_chargeable_amount_in_gbp, - coalesce(chargeable.unique_chargeable_bookings, 0) as unique_chargeable_bookings, - coalesce(chargeable.unique_chargeable_listings, 0) as unique_chargeable_listings -from all_dates d -left join - int_kpis__agg_monthly_new_dash_created_services created - on d.date = created.end_date - and d.dimension = created.dimension - and d.dimension_value = created.dimension_value -left join - int_kpis__agg_monthly_new_dash_chargeable_services chargeable - on d.date = chargeable.end_date - and d.dimension = chargeable.dimension - and d.dimension_value = chargeable.dimension_value -left join - int_kpis__agg_monthly_new_dash_deals_offered_services deals - on d.date = deals.date - and d.dimension = deals.dimension - and d.dimension_value = deals.dimension_value -left join - int_kpis__agg_monthly_new_dash_accommodation_offered_services accommodation - on d.date = accommodation.date - and d.dimension = accommodation.dimension - and d.dimension_value = accommodation.dimension_value -left join - int_kpis__agg_monthly_new_dash_created_bookings bookings - on d.date = bookings.end_date - and d.dimension = bookings.dimension - and d.dimension_value = bookings.dimension_value -where d.is_end_of_month +select * +from ({{ generate_kpis_aggregation("monthly", agg_models) }})