From fb2b2def52d9a95a9baea9c73533ac8fc6243e57 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Mon, 31 Mar 2025 14:53:20 +0200 Subject: [PATCH 1/8] New created bookings with services model --- ...ew_dash_created_bookings_with_services.sql | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings_with_services.sql diff --git a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings_with_services.sql b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings_with_services.sql new file mode 100644 index 0000000..cb86f98 --- /dev/null +++ b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings_with_services.sql @@ -0,0 +1,36 @@ +{{ + config( + materialized="table", + unique_key=["id_booking", "service_name", "date", "service_business_type"], + ) +}} +select + -- Unique Key -- + icbs.id_booking, + date(icbs.booking_created_date_utc) as date, + coalesce(icbsd.service_name) as service_name, + coalesce(icbsd.service_business_type, 'UNSET') as service_business_type, + -- Dimensions -- + coalesce(icbs.id_deal, 'UNSET') as id_deal, + case when icbsd.is_upgraded_service then 'YES' else 'NO' end as is_upgraded_service, + coalesce(icbs.new_dash_version, 'UNSET') as new_dash_version, + coalesce( + icd.main_billing_country_iso_3_per_deal, 'UNSET' + ) as main_billing_country_iso_3_per_deal, + coalesce( + icmas.active_accommodations_per_deal_segmentation, 'UNSET' + ) as active_accommodations_per_deal_segmentation +from {{ ref("int_core__booking_summary") }} as icbs +inner join + {{ ref("int_core__booking_service_detail") }} as icbsd + on icbs.id_booking = icbsd.id_booking +left join {{ ref("int_core__deal") }} as icd on icbs.id_deal = icd.id_deal +left join + {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas + on icbs.id_deal = icmas.id_deal + and date(icbsd.service_detail_created_at_utc) = icmas.date +where + icbs.is_user_in_new_dash = true + and icbs.is_missing_id_deal = false + and icbsd.service_detail_created_at_utc + >= icbs.user_in_new_dash_since_timestamp_at_utc From 2a797ce0e85bdaa889e3870adacb090d1f7d48e8 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 1 Apr 2025 09:14:30 +0200 Subject: [PATCH 2/8] New dash bookings agg models --- macros/business_kpis_configuration.sql | 9 ++ ...s__agg_daily_new_dash_created_bookings.sql | 23 +++++ ..._agg_monthly_new_dash_created_bookings.sql | 20 +++++ ...__agg_weekly_new_dash_created_bookings.sql | 20 +++++ ...metric_daily_new_dash_created_bookings.sql | 43 +++++++++ ...ew_dash_created_bookings_with_services.sql | 36 -------- ...tric_monthly_new_dash_created_bookings.sql | 33 +++++++ ...etric_weekly_new_dash_created_bookings.sql | 33 +++++++ ...int_kpis__product_new_dash_agg_metrics.sql | 90 +++++++++++-------- .../kpis__product_new_dash_agg_metrics.sql | 2 +- 10 files changed, 236 insertions(+), 73 deletions(-) create mode 100644 models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_bookings.sql create mode 100644 models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_bookings.sql create mode 100644 models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_bookings.sql create mode 100644 models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings.sql delete mode 100644 models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings_with_services.sql create mode 100644 models/intermediate/kpis/int_kpis__metric_monthly_new_dash_created_bookings.sql create mode 100644 models/intermediate/kpis/int_kpis__metric_weekly_new_dash_created_bookings.sql diff --git a/macros/business_kpis_configuration.sql b/macros/business_kpis_configuration.sql index 3b3f797..6d0ef66 100644 --- a/macros/business_kpis_configuration.sql +++ b/macros/business_kpis_configuration.sql @@ -207,6 +207,15 @@ Provides a general assignement for the Dimensions available for each KPI ] %} {% 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/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 new file mode 100644 index 0000000..77dd889 --- /dev/null +++ b/models/intermediate/kpis/int_kpis__agg_daily_new_dash_created_bookings.sql @@ -0,0 +1,23 @@ +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %} + +{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} + + +{% for dimension in dimensions %} + select + -- Unique Key -- + d.date, + {{ dimension.dimension }} as dimension, + {{ dimension.dimension_value }} as dimension_value, + -- 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") }} as cbs + on d.date = cbs.date + where cbs.id_deal is not null + group by 1, 2, 3 + {% if not loop.last %} + union all + {% endif %} +{% endfor %} 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 new file mode 100644 index 0000000..42f5673 --- /dev/null +++ b/models/intermediate/kpis/int_kpis__agg_monthly_new_dash_created_bookings.sql @@ -0,0 +1,20 @@ +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %} + +{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} + + +{% for dimension in dimensions %} + select + -- Unique Key -- + start_date, + end_date, + {{ dimension.dimension }} as dimension, + {{ dimension.dimension_value }} as dimension_value, + -- Metrics -- + sum(created_bookings) as created_bookings + from {{ ref("int_kpis__metric_monthly_new_dash_created_bookings") }} + group by 1, 2, 3, 4 + {% if not loop.last %} + union all + {% endif %} +{% endfor %} 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 new file mode 100644 index 0000000..a99ff1d --- /dev/null +++ b/models/intermediate/kpis/int_kpis__agg_weekly_new_dash_created_bookings.sql @@ -0,0 +1,20 @@ +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %} + +{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} + + +{% for dimension in dimensions %} + select + -- Unique Key -- + start_date, + end_date, + {{ dimension.dimension }} as dimension, + {{ dimension.dimension_value }} as dimension_value, + -- Metrics -- + sum(created_bookings) as created_bookings + from {{ ref("int_kpis__metric_weekly_new_dash_created_bookings") }} + group by 1, 2, 3, 4 + {% if not loop.last %} + union all + {% endif %} +{% endfor %} 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 new file mode 100644 index 0000000..132d451 --- /dev/null +++ b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings.sql @@ -0,0 +1,43 @@ +{{ + config( + materialized="table", + unique_key=[ + "date", + "id_deal", + "id_user_product_bundle", + "service_name", + "service_business_type", + ], + ) +}} +select + -- Unique Key -- + date(bs.booking_created_date_utc) as date, + bs.id_booking, + bs.id_user_product_bundle, + coalesce(icbsd.service_name) as service_name, + coalesce(icbsd.service_business_type, 'UNSET') as service_business_type, + -- Dimensions -- + coalesce(bs.id_deal, 'UNSET') as id_deal, + case when icbsd.is_upgraded_service then 'YES' else 'NO' end as is_upgraded_service, + coalesce(bs.new_dash_version, 'UNSET') as new_dash_version, + coalesce( + uh.main_billing_country_iso_3_per_deal, 'UNSET' + ) as main_billing_country_iso_3_per_deal, + coalesce( + icmas.active_accommodations_per_deal_segmentation, 'UNSET' + ) as active_accommodations_per_deal_segmentation +from {{ ref("int_core__booking_summary") }} as bs +inner join + {{ ref("int_core__booking_service_detail") }} as icbsd + on bs.id_booking = icbsd.id_booking +inner join {{ ref("int_core__user_host") }} as uh on bs.id_user_host = uh.id_user_host +left join + {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas + on bs.id_deal = icmas.id_deal + and date(icbsd.service_detail_created_at_utc) = icmas.date +where + bs.is_user_in_new_dash = true + and bs.is_missing_id_deal = false + and icbsd.service_detail_created_at_utc + >= bs.user_in_new_dash_since_timestamp_at_utc diff --git a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings_with_services.sql b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings_with_services.sql deleted file mode 100644 index cb86f98..0000000 --- a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_created_bookings_with_services.sql +++ /dev/null @@ -1,36 +0,0 @@ -{{ - config( - materialized="table", - unique_key=["id_booking", "service_name", "date", "service_business_type"], - ) -}} -select - -- Unique Key -- - icbs.id_booking, - date(icbs.booking_created_date_utc) as date, - coalesce(icbsd.service_name) as service_name, - coalesce(icbsd.service_business_type, 'UNSET') as service_business_type, - -- Dimensions -- - coalesce(icbs.id_deal, 'UNSET') as id_deal, - case when icbsd.is_upgraded_service then 'YES' else 'NO' end as is_upgraded_service, - coalesce(icbs.new_dash_version, 'UNSET') as new_dash_version, - coalesce( - icd.main_billing_country_iso_3_per_deal, 'UNSET' - ) as main_billing_country_iso_3_per_deal, - coalesce( - icmas.active_accommodations_per_deal_segmentation, 'UNSET' - ) as active_accommodations_per_deal_segmentation -from {{ ref("int_core__booking_summary") }} as icbs -inner join - {{ ref("int_core__booking_service_detail") }} as icbsd - on icbs.id_booking = icbsd.id_booking -left join {{ ref("int_core__deal") }} as icd on icbs.id_deal = icd.id_deal -left join - {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas - on icbs.id_deal = icmas.id_deal - and date(icbsd.service_detail_created_at_utc) = icmas.date -where - icbs.is_user_in_new_dash = true - and icbs.is_missing_id_deal = false - and icbsd.service_detail_created_at_utc - >= icbs.user_in_new_dash_since_timestamp_at_utc diff --git a/models/intermediate/kpis/int_kpis__metric_monthly_new_dash_created_bookings.sql b/models/intermediate/kpis/int_kpis__metric_monthly_new_dash_created_bookings.sql new file mode 100644 index 0000000..c69b772 --- /dev/null +++ b/models/intermediate/kpis/int_kpis__metric_monthly_new_dash_created_bookings.sql @@ -0,0 +1,33 @@ +{{ + 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 diff --git a/models/intermediate/kpis/int_kpis__metric_weekly_new_dash_created_bookings.sql b/models/intermediate/kpis/int_kpis__metric_weekly_new_dash_created_bookings.sql new file mode 100644 index 0000000..e611fd7 --- /dev/null +++ b/models/intermediate/kpis/int_kpis__metric_weekly_new_dash_created_bookings.sql @@ -0,0 +1,33 @@ +{{ + 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 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 701d6c0..0208e83 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 @@ -38,6 +38,15 @@ with 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 @@ -70,9 +79,7 @@ select accommodation.accommodation_with_offered_service_count, 0 ) as accommodation_with_offered_service_count, coalesce(created.created_services, 0) as created_services, - coalesce( - created.booking_with_created_services_count, 0 - ) as booking_with_created_services_count, + 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 @@ -87,19 +94,24 @@ left join and d.dimension_value = created.dimension_value left join int_kpis__agg_daily_new_dash_chargeable_services chargeable - on created.date = chargeable.date - and created.dimension = chargeable.dimension - and created.dimension_value = chargeable.dimension_value + 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 created.date = deals.date - and created.dimension = deals.dimension - and created.dimension_value = deals.dimension_value + 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 created.date = accommodation.date - and created.dimension = accommodation.dimension - and created.dimension_value = accommodation.dimension_value + 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 union all select d.date, @@ -113,9 +125,7 @@ select accommodation.accommodation_with_offered_service_count, 0 ) as accommodation_with_offered_service_count, coalesce(created.created_services, 0) as created_services, - coalesce( - created.booking_with_created_services_count, 0 - ) as booking_with_created_services_count, + 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 @@ -130,19 +140,24 @@ left join and d.dimension_value = created.dimension_value left join int_kpis__agg_weekly_new_dash_chargeable_services chargeable - on created.end_date = chargeable.end_date - and created.dimension = chargeable.dimension - and created.dimension_value = chargeable.dimension_value + 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 created.end_date = deals.date - and created.dimension = deals.dimension - and created.dimension_value = deals.dimension_value + 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 created.end_date = accommodation.date - and created.dimension = accommodation.dimension - and created.dimension_value = accommodation.dimension_value + 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 union all select @@ -157,9 +172,7 @@ select accommodation.accommodation_with_offered_service_count, 0 ) as accommodation_with_offered_service_count, coalesce(created.created_services, 0) as created_services, - coalesce( - created.booking_with_created_services_count, 0 - ) as booking_with_created_services_count, + 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 @@ -174,17 +187,22 @@ left join and d.dimension_value = created.dimension_value left join int_kpis__agg_monthly_new_dash_chargeable_services chargeable - on created.end_date = chargeable.end_date - and created.dimension = chargeable.dimension - and created.dimension_value = chargeable.dimension_value + 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 created.end_date = deals.date - and created.dimension = deals.dimension - and created.dimension_value = deals.dimension_value + 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 created.end_date = accommodation.date - and created.dimension = accommodation.dimension - and created.dimension_value = accommodation.dimension_value + 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 diff --git a/models/reporting/kpis/kpis__product_new_dash_agg_metrics.sql b/models/reporting/kpis/kpis__product_new_dash_agg_metrics.sql index 384abd4..c09e00d 100644 --- a/models/reporting/kpis/kpis__product_new_dash_agg_metrics.sql +++ b/models/reporting/kpis/kpis__product_new_dash_agg_metrics.sql @@ -11,7 +11,7 @@ select deal_with_offered_service_count as deal_with_offered_service_count, accommodation_with_offered_service_count as accommodation_with_offered_service_count, - booking_with_created_services_count as booking_with_created_services_count, + created_bookings_count as created_bookings_count, total_chargeable_services as total_chargeable_services, total_chargeable_amount_in_gbp as total_chargeable_amount_in_gbp, unique_chargeable_bookings as unique_chargeable_bookings, From 264ce4e20324a459056113e8d02c37e918a6f0b6 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 1 Apr 2025 14:24:14 +0200 Subject: [PATCH 3/8] Fixed model aggregations --- ..._agg_monthly_new_dash_created_bookings.sql | 12 ++++--- ...__agg_weekly_new_dash_created_bookings.sql | 12 ++++--- ...tric_monthly_new_dash_created_bookings.sql | 33 ------------------- ...etric_weekly_new_dash_created_bookings.sql | 33 ------------------- 4 files changed, 16 insertions(+), 74 deletions(-) delete mode 100644 models/intermediate/kpis/int_kpis__metric_monthly_new_dash_created_bookings.sql delete mode 100644 models/intermediate/kpis/int_kpis__metric_weekly_new_dash_created_bookings.sql 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 42f5673..185c844 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 @@ -6,13 +6,17 @@ {% for dimension in dimensions %} select -- Unique Key -- - start_date, - end_date, + d.first_day_month as start_date, + d.date as end_date, {{ dimension.dimension }} as dimension, {{ dimension.dimension_value }} as dimension_value, -- Metrics -- - sum(created_bookings) as created_bookings - from {{ ref("int_kpis__metric_monthly_new_dash_created_bookings") }} + count(distinct dcb.id_booking) as 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 {% if not loop.last %} union all 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 a99ff1d..5bf664a 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 @@ -6,13 +6,17 @@ {% for dimension in dimensions %} select -- Unique Key -- - start_date, - end_date, + d.first_day_month as start_date, + d.date as end_date, {{ dimension.dimension }} as dimension, {{ dimension.dimension_value }} as dimension_value, -- Metrics -- - sum(created_bookings) as created_bookings - from {{ ref("int_kpis__metric_weekly_new_dash_created_bookings") }} + count(distinct dcb.id_booking) as 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 {% if not loop.last %} union all diff --git a/models/intermediate/kpis/int_kpis__metric_monthly_new_dash_created_bookings.sql b/models/intermediate/kpis/int_kpis__metric_monthly_new_dash_created_bookings.sql deleted file mode 100644 index c69b772..0000000 --- a/models/intermediate/kpis/int_kpis__metric_monthly_new_dash_created_bookings.sql +++ /dev/null @@ -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 diff --git a/models/intermediate/kpis/int_kpis__metric_weekly_new_dash_created_bookings.sql b/models/intermediate/kpis/int_kpis__metric_weekly_new_dash_created_bookings.sql deleted file mode 100644 index e611fd7..0000000 --- a/models/intermediate/kpis/int_kpis__metric_weekly_new_dash_created_bookings.sql +++ /dev/null @@ -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 From 60dfae5cf466b707a3bd7f2e30e956fef074bde1 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 1 Apr 2025 19:51:30 +0200 Subject: [PATCH 4/8] 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) }}) From 78e2474a876795c4094909a317f6b4c80261a4fc Mon Sep 17 00:00:00 2001 From: Joaquin Date: Wed, 2 Apr 2025 08:22:21 +0200 Subject: [PATCH 5/8] Update reporting model --- models/intermediate/kpis/schema.yml | 9 +++------ .../kpis/kpis__product_new_dash_agg_metrics.sql | 2 +- models/reporting/kpis/schema.yml | 9 +++------ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/models/intermediate/kpis/schema.yml b/models/intermediate/kpis/schema.yml index f96fd9b..bda9380 100644 --- a/models/intermediate/kpis/schema.yml +++ b/models/intermediate/kpis/schema.yml @@ -6727,14 +6727,11 @@ models: The created services for a given time granularity, date or dates range, dimension and value. - - name: booking_with_created_services_count + - name: created_bookings data_type: bigint description: | - The bookings with created services for a given time granularity, date or - dates range, dimension and value. - This is an approximation to booking count since different services can - apply to the same booking and these do not need to be created in the same - time period. Therefore, it's not an additive metric. + The amount of created bookings for a given time granularity, date or dates range, + dimension and value. - name: total_chargeable_services data_type: integer diff --git a/models/reporting/kpis/kpis__product_new_dash_agg_metrics.sql b/models/reporting/kpis/kpis__product_new_dash_agg_metrics.sql index c09e00d..bbdb31f 100644 --- a/models/reporting/kpis/kpis__product_new_dash_agg_metrics.sql +++ b/models/reporting/kpis/kpis__product_new_dash_agg_metrics.sql @@ -11,7 +11,7 @@ select deal_with_offered_service_count as deal_with_offered_service_count, accommodation_with_offered_service_count as accommodation_with_offered_service_count, - created_bookings_count as created_bookings_count, + created_bookings as created_bookings, total_chargeable_services as total_chargeable_services, total_chargeable_amount_in_gbp as total_chargeable_amount_in_gbp, unique_chargeable_bookings as unique_chargeable_bookings, diff --git a/models/reporting/kpis/schema.yml b/models/reporting/kpis/schema.yml index 0bbe918..79da89d 100644 --- a/models/reporting/kpis/schema.yml +++ b/models/reporting/kpis/schema.yml @@ -327,14 +327,11 @@ models: description: | The count of accommodations with services offered by a given date, dimension and value. - - name: booking_with_created_services_count + - name: created_bookings data_type: bigint description: | - The bookings with created services for a given time granularity, date or - dates range, dimension and value. - This is an approximation to booking count since different services can - apply to the same booking and these do not need to be created in the same - time period. Therefore, it's not an additive metric. + The amount of created bookings for a given time granularity, date or dates range, + dimension and value. - name: total_chargeable_services data_type: integer From ab179577b15dcfb89164fd8207380a7eec24a94d Mon Sep 17 00:00:00 2001 From: Joaquin Date: Wed, 2 Apr 2025 12:01:57 +0200 Subject: [PATCH 6/8] removed macro and kept all logic inside the model --- macros/business_kpis_configuration.sql | 17 ++++----- 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 +- ...int_kpis__product_new_dash_agg_metrics.sql | 35 ++++++++++++++----- 15 files changed, 52 insertions(+), 53 deletions(-) delete mode 100644 macros/generate_kpis_aggregation.sql diff --git a/macros/business_kpis_configuration.sql b/macros/business_kpis_configuration.sql index 321559c..11e4aaf 100644 --- a/macros/business_kpis_configuration.sql +++ b/macros/business_kpis_configuration.sql @@ -171,16 +171,13 @@ Provides a general assignement for the Dimensions available for each KPI ] %} {% endif %} - {% if entity_name == "NEW_DASH" %} - {% 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_DEALS_OFFERED_SERVICES" %} + {% if entity_name in [ + "NEW_DASH_CREATED_SERVICES", + "NEW_DASH_CHARGEABLE_SERVICES", + "NEW_DASH_ACCOMMODATION_OFFERED_SERVICES", + "NEW_DASH_CREATED_BOOKINGS", + "NEW_DASH_DEALS_OFFERED_SERVICES", + ] %} {% set additional_dimensions = additional_dimensions + [ dim_has_upgraded_service(), dim_new_dash_version(), diff --git a/macros/generate_kpis_aggregation.sql b/macros/generate_kpis_aggregation.sql deleted file mode 100644 index 5ce9bbc..0000000 --- a/macros/generate_kpis_aggregation.sql +++ /dev/null @@ -1,23 +0,0 @@ -{% 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 3c00223..080395d 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,4 +1,6 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} +{% set dimensions = get_kpi_dimensions_per_model( + "NEW_DASH_ACCOMMODATION_OFFERED_SERVICES" +) %} {{ 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 7802dc3..2b66697 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") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CHARGEABLE_SERVICES") %} {{ 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 4fae871..77dd889 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") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %} {{ 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 f3f74c2..2b1ac06 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") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_SERVICES") %} {{ 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 64ce35e..7d82a9c 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,4 +1,6 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} +{% set dimensions = get_kpi_dimensions_per_model( + "NEW_DASH_ACCOMMODATION_OFFERED_SERVICES" +) %} {{ 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 ab73cb5..f28c863 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") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CHARGEABLE_SERVICES") %} {{ 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 9239d5c..185c844 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") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %} {{ 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 931c761..0525434 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") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_SERVICES") %} {{ 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 97d8129..a353a74 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,4 +1,6 @@ -{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %} +{% set dimensions = get_kpi_dimensions_per_model( + "NEW_DASH_ACCOMMODATION_OFFERED_SERVICES" +) %} {{ 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 f061305..243a6be 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") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CHARGEABLE_SERVICES") %} {{ 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 488c312..5bf664a 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") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %} {{ 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 b27b261..eeb5de1 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") %} +{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_SERVICES") %} {{ config( 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 3efa1a3..f6719e2 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 @@ -119,11 +119,30 @@ with left join int_kpis__dimension_dates d on c.date = d.date ) -select * -from ({{ generate_kpis_aggregation("daily", agg_models) }}) -union all -select * -from ({{ generate_kpis_aggregation("weekly", agg_models) }}) -union all -select * -from ({{ generate_kpis_aggregation("monthly", agg_models) }}) +{% for time_granularity in ["daily", "weekly", "monthly"] %} + {% if time_granularity != "daily" %} + union all + {% endif %} + + 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 %} +{% endfor %} From e8da311463582ed1c80a205df41c8ab6f6167cce Mon Sep 17 00:00:00 2001 From: Joaquin Date: Wed, 2 Apr 2025 12:07:39 +0200 Subject: [PATCH 7/8] Readded schema --- models/intermediate/kpis/schema.yml | 281 ++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) diff --git a/models/intermediate/kpis/schema.yml b/models/intermediate/kpis/schema.yml index bda9380..67e4128 100644 --- a/models/intermediate/kpis/schema.yml +++ b/models/intermediate/kpis/schema.yml @@ -8343,3 +8343,284 @@ models: description: | The month-to-date Revenue Retained Post-Resolutions in GBP for a given date, dimension and value. + + - name: int_kpis__metric_daily_new_dash_created_bookings + description: | + This model computes the Daily Created Bookings with Services at the deepest granularity. + It only retrieves services that come from users that are in New Dash, as well + as it only considers services created after the user has moved to New Dash. + The unique key corresponds to the deepest granularity of the model, + in this case: + - date, + - id_booking, + - id_user_product_bundle, + - service_name, + - service_business_type + + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - date + - id_booking + - id_user_product_bundle + - service_name + - service_business_type + + columns: + - name: date + data_type: date + description: Date of when the Booking was created. + data_tests: + - not_null + + - name: id_booking + data_type: bigint + description: Unique identifier of the Booking. + data_tests: + - not_null + + - name: id_user_product_bundle + data_type: bigint + description: Unique identifier of the User Product Bundle. + data_tests: + - not_null + + - name: service_name + data_type: string + description: Name of the created service. + data_tests: + - not_null + + - name: id_deal + data_type: string + description: Unique identifier of an account. + data_tests: + - not_null + + - name: is_upgraded_service + data_type: string + description: | + Whether the service is an upgraded version of the + default. In other words, if it's not Basic Screening. + data_tests: + - not_null + - accepted_values: + values: + - "YES" + - "NO" + + - name: service_business_type + data_type: string + description: | + Identifies the service type (Screening, Deposit Management, Protection + or Guest Agreement) according to New Pricing documentation. + Cannot be null. + data_tests: + - not_null + - accepted_values: + values: + - "SCREENING" + - "PROTECTION" + - "DEPOSIT_MANAGEMENT" + - "GUEST_AGREEMENT" + - "UNKNOWN" + - "UNSET" + + - name: new_dash_version + data_type: string + description: | + The version of the New Dash. It corresponds to the + release or migration phase from user point of view. + data_tests: + - not_null + + - name: active_accommodations_per_deal_segmentation + data_type: string + description: | + Segment value based on the number of listings booked in 12 months + for a given deal and date. + data_tests: + - not_null + - accepted_values: + values: + - "0" + - "01-05" + - "06-20" + - "21-60" + - "61+" + - "UNSET" + + - name: main_billing_country_iso_3_per_deal + data_type: string + description: | + Main billing country of the host aggregated at Deal level. + data_tests: + - not_null + + - name: int_kpis__agg_weekly_new_dash_created_bookings + description: | + This model computes the dimension aggregation for Weekly Created Bookings with Services. + It only retrieves services that come from users that are in New Dash, as well + as it only considers services created after the user has moved to New Dash. + The primary key of this model is end_date, dimension and dimension_value. + + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - end_date + - dimension + - dimension_value + + columns: + - name: start_date + data_type: date + description: | + The start date of the time range considered for the metrics in this record. + data_tests: + - not_null + + - name: end_date + data_type: date + description: | + The end date of the time range considered for the metrics in this record. + data_tests: + - not_null + + - name: dimension + data_type: string + description: The dimension or granularity of the metrics. + data_tests: + - assert_dimension_completeness: + metric_column_names: + - created_bookings + where: "dimension in ('by_number_of_listings', 'by_billing_country', 'by_new_dash_version', 'by_deal')" + - accepted_values: + values: + - global + - by_number_of_listings + - by_billing_country + - by_deal + - by_new_dash_version + - by_has_upgraded_service + - by_service + - by_service_business_type + + - name: dimension_value + data_type: string + description: The value or segment available for the selected dimension. + data_tests: + - not_null + + - name: created_bookings + data_type: bigint + description: The weekly created bookings for a given date range, dimension and value. + + - name: int_kpis__agg_monthly_new_dash_created_bookings + description: | + This model computes the dimension aggregation for Monthly Created Bookings with Services. + It only retrieves services that come from users that are in New Dash, as well + as it only considers services created after the user has moved to New Dash. + The primary key of this model is end_date, dimension and dimension_value. + + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - end_date + - dimension + - dimension_value + + columns: + - name: start_date + data_type: date + description: | + The start date of the time range considered for the metrics in this record. + data_tests: + - not_null + + - name: end_date + data_type: date + description: | + The end date of the time range considered for the metrics in this record. + data_tests: + - not_null + + - name: dimension + data_type: string + description: The dimension or granularity of the metrics. + data_tests: + - assert_dimension_completeness: + metric_column_names: + - created_bookings + where: "dimension in ('by_number_of_listings', 'by_billing_country', 'by_new_dash_version', 'by_deal')" + - accepted_values: + values: + - global + - by_number_of_listings + - by_billing_country + - by_deal + - by_new_dash_version + - by_has_upgraded_service + - by_service + - by_service_business_type + + - name: dimension_value + data_type: string + description: The value or segment available for the selected dimension. + data_tests: + - not_null + + - name: created_bookings + data_type: bigint + description: The monthly created bookings for a given date range, dimension and value. + + - name: int_kpis__agg_daily_new_dash_created_bookings + description: | + This model computes the dimension aggregation for Daily Created Bookings with Services. + It only retrieves services that come from users that are in New Dash, as well + as it only considers services created after the user has moved to New Dash. + The primary key of this model is date, dimension and dimension_value. + + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - date + - dimension + - dimension_value + + columns: + - name: date + data_type: date + description: | + The daily date acting as time range for the metrics in this record. + data_tests: + - not_null + + - name: dimension + data_type: string + description: The dimension or granularity of the metrics. + data_tests: + - assert_dimension_completeness: + metric_column_names: + - created_bookings + where: "dimension in ('by_number_of_listings', 'by_billing_country', 'by_new_dash_version', 'by_deal')" + - accepted_values: + values: + - global + - by_number_of_listings + - by_billing_country + - by_deal + - by_new_dash_version + - by_has_upgraded_service + - by_service + - by_service_business_type + + - name: dimension_value + data_type: string + description: The value or segment available for the selected dimension. + data_tests: + - not_null + + - name: created_bookings + data_type: bigint + description: The daily created bookings for a given date, dimension and value. + From 4c011d70634d3f3d1c6ebf0095eacd3983e9b9c1 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Wed, 2 Apr 2025 12:55:04 +0200 Subject: [PATCH 8/8] Changed loop --- .../kpis/int_kpis__product_new_dash_agg_metrics.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 f6719e2..88b174f 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 @@ -120,10 +120,6 @@ with ) {% for time_granularity in ["daily", "weekly", "monthly"] %} - {% if time_granularity != "daily" %} - union all - {% endif %} - select d.date, '{{ time_granularity }}' as time_granularity, @@ -145,4 +141,8 @@ with {% if time_granularity == "weekly" %} where d.is_end_of_week {% elif time_granularity == "monthly" %} where d.is_end_of_month {% endif %} + + {% if not loop.last %} + union all + {% endif %} {% endfor %}