aggregated to agg

This commit is contained in:
Joaquin 2024-11-05 12:17:26 +01:00
parent f601b69c7d
commit 092e37d58c
28 changed files with 94 additions and 94 deletions

View file

@ -1,9 +1,9 @@
{{ config(materialized="table", unique_key=["date", "id_deal"]) }}
with
int_monthly_aggregated_metrics_history_by_deal as (
select * from {{ ref("int_monthly_aggregated_metrics_history_by_deal") }}
int_monthly_agg_metrics_history_by_deal as (
select * from {{ ref("int_monthly_agg_metrics_history_by_deal") }}
),
aggregated_metrics_by_deal_over_12_months as (
agg_metrics_by_deal_over_12_months as (
select
am.date,
am.id_deal,
@ -28,7 +28,7 @@ with
order by am.date
rows between 12 preceding and 1 preceding
) as sum_listings_booked_in_month_preceding_12_months
from int_monthly_aggregated_metrics_history_by_deal am
from int_monthly_agg_metrics_history_by_deal am
),
global_computation_over_12_months as (
select
@ -73,7 +73,7 @@ with
) over (partition by ambd.date)
as avg_global_listings_booked_in_month_preceding_12_months
from aggregated_metrics_by_deal_over_12_months ambd
from agg_metrics_by_deal_over_12_months ambd
)
select
id_deal,

View file

@ -10,47 +10,47 @@ with
),
created_bookings as (
select *
from {{ ref("int_kpis__aggregated_monthly_created_bookings") }}
from {{ ref("int_kpis__agg_monthly_created_bookings") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
check_out_bookings as (
select *
from {{ ref("int_kpis__aggregated_monthly_check_out_bookings") }}
from {{ ref("int_kpis__agg_monthly_check_out_bookings") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
cancelled_bookings as (
select *
from {{ ref("int_kpis__aggregated_monthly_cancelled_bookings") }}
from {{ ref("int_kpis__agg_monthly_cancelled_bookings") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
billable_bookings as (
select *
from {{ ref("int_kpis__aggregated_monthly_billable_bookings") }}
from {{ ref("int_kpis__agg_monthly_billable_bookings") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
created_guest_journeys as (
select *
from {{ ref("int_kpis__aggregated_monthly_created_guest_journeys") }}
from {{ ref("int_kpis__agg_monthly_created_guest_journeys") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
started_guest_journeys as (
select *
from {{ ref("int_kpis__aggregated_monthly_started_guest_journeys") }}
from {{ ref("int_kpis__agg_monthly_started_guest_journeys") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
completed_guest_journeys as (
select *
from {{ ref("int_kpis__aggregated_monthly_completed_guest_journeys") }}
from {{ ref("int_kpis__agg_monthly_completed_guest_journeys") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
guest_journeys_with_payment as (
select *
from {{ ref("int_kpis__aggregated_monthly_guest_journeys_with_payment") }}
from {{ ref("int_kpis__agg_monthly_guest_journeys_with_payment") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
guest_payments as (
select *
from {{ ref("int_kpis__aggregated_monthly_guest_payments") }}
from {{ ref("int_kpis__agg_monthly_guest_payments") }}
where dimension in ('by_deal') and dimension_value <> 'UNSET'
),
int_xero__monthly_invoicing_history_by_deal as (

View file

@ -1,7 +1,7 @@
{{ config(materialized="table", unique_key=["date", "id_deal"]) }}
with
int_monthly_aggregated_metrics_history_by_deal as (
select * from {{ ref("int_monthly_aggregated_metrics_history_by_deal") }}
int_monthly_agg_metrics_history_by_deal as (
select * from {{ ref("int_monthly_agg_metrics_history_by_deal") }}
),
int_hubspot__deal as (select * from {{ ref("int_hubspot__deal") }}),
deal_history_from_previous_months as (
@ -17,7 +17,7 @@ with
coalesce(total_revenue_in_gbp, 0) as revenue_in_gbp,
coalesce(created_bookings, 0) as created_bookings,
coalesce(listings_booked_in_month, 0) as listings_booked_in_month
from int_monthly_aggregated_metrics_history_by_deal am
from int_monthly_agg_metrics_history_by_deal am
-- Do not show data of ongoing month
where am.date < date_trunc('month', current_date)::date
),
@ -71,7 +71,7 @@ with
coalesce(sum(previous_twelve_months.revenue_in_gbp), 0), 0
) as effective_deal_revenue_12_months_window
from deal_history_from_previous_months as given_month
-- Retrieve aggregated data from same deal from the previous twelve
-- Retrieve agg data from same deal from the previous twelve
-- months
left join
deal_history_from_previous_months as previous_twelve_months
@ -81,7 +81,7 @@ with
and given_month.first_day_month
>= previous_twelve_months.first_day_month + interval '1 months'
group by 1, 2
) as aggregated_revenue_data_before_partition
) as agg_revenue_data_before_partition
),
metrics_attribution_to_given_month_per_deal as (
select
@ -100,10 +100,10 @@ with
previous_2_month.first_day_month as previous_2_month_first_day_month,
previous_12_month.first_day_month as previous_12_month_first_day_month,
previous_13_month.first_day_month as previous_13_month_first_day_month,
aggregated_12m_window.from_first_day_month
as aggregated_revenue_from_first_day_month,
aggregated_12m_window.to_first_day_month
as aggregated_revenue_to_first_day_month,
agg_12m_window.from_first_day_month
as agg_revenue_from_first_day_month,
agg_12m_window.to_first_day_month
as agg_revenue_to_first_day_month,
-- Revenue --
given_month.revenue_in_gbp as given_month_revenue_in_gbp,
@ -154,54 +154,54 @@ with
-- 12 Months Window (Account Size) --
-- Bookings --
aggregated_12m_window.deal_created_bookings_12_months_window,
aggregated_12m_window.global_created_bookings_12_months_window,
agg_12m_window.deal_created_bookings_12_months_window,
agg_12m_window.global_created_bookings_12_months_window,
coalesce(
cast(
aggregated_12m_window.deal_created_bookings_12_months_window
agg_12m_window.deal_created_bookings_12_months_window
as decimal
) / nullif(
aggregated_12m_window.global_created_bookings_12_months_window, 0
agg_12m_window.global_created_bookings_12_months_window, 0
),
0
) as deal_contribution_share_to_global_created_bookings,
aggregated_12m_window.deal_contribution_rank_to_global_created_bookings,
agg_12m_window.deal_contribution_rank_to_global_created_bookings,
-- Listings --
round(
aggregated_12m_window.deal_avg_listings_booked_in_month_12_months_window,
agg_12m_window.deal_avg_listings_booked_in_month_12_months_window,
2
) as deal_avg_listings_booked_in_month_12_months_window,
round(
aggregated_12m_window.global_avg_listings_booked_in_month_12_months_window,
agg_12m_window.global_avg_listings_booked_in_month_12_months_window,
2
) as global_avg_listings_booked_in_month_12_months_window,
coalesce(
cast(
aggregated_12m_window.deal_avg_listings_booked_in_month_12_months_window
agg_12m_window.deal_avg_listings_booked_in_month_12_months_window
as decimal
) / nullif(
aggregated_12m_window.global_avg_listings_booked_in_month_12_months_window,
agg_12m_window.global_avg_listings_booked_in_month_12_months_window,
0
),
0
) as deal_contribution_share_to_global_avg_listings_booked_in_month,
aggregated_12m_window.deal_contribution_rank_to_global_avg_listings_booked_in_month,
agg_12m_window.deal_contribution_rank_to_global_avg_listings_booked_in_month,
-- Revenue --
aggregated_12m_window.deal_revenue_12_months_window,
aggregated_12m_window.effective_deal_revenue_12_months_window,
aggregated_12m_window.effective_global_revenue_12_months_window,
agg_12m_window.deal_revenue_12_months_window,
agg_12m_window.effective_deal_revenue_12_months_window,
agg_12m_window.effective_global_revenue_12_months_window,
coalesce(
cast(
aggregated_12m_window.effective_deal_revenue_12_months_window
agg_12m_window.effective_deal_revenue_12_months_window
as decimal
) / nullif(
aggregated_12m_window.effective_global_revenue_12_months_window, 0
agg_12m_window.effective_global_revenue_12_months_window, 0
),
0
) as deal_contribution_share_to_global_revenue,
aggregated_12m_window.deal_contribution_rank_to_global_revenue
agg_12m_window.deal_contribution_rank_to_global_revenue
from deal_history_from_previous_months as given_month
-- Retrieve monthly data from same deal and previous month
@ -232,9 +232,9 @@ with
and previous_13_month.id_deal = given_month.id_deal
-- Retrieve aggregation over 12 previous months
left join
revenue_12_months_window_aggregation_per_deal aggregated_12m_window
on aggregated_12m_window.id_deal = given_month.id_deal
and aggregated_12m_window.first_day_month = given_month.first_day_month
revenue_12_months_window_aggregation_per_deal agg_12m_window
on agg_12m_window.id_deal = given_month.id_deal
and agg_12m_window.first_day_month = given_month.first_day_month
),
growth_score_computation as (
select
@ -250,8 +250,8 @@ with
m.previous_2_month_first_day_month,
m.previous_12_month_first_day_month,
m.previous_13_month_first_day_month,
m.aggregated_revenue_from_first_day_month,
m.aggregated_revenue_to_first_day_month,
m.agg_revenue_from_first_day_month,
m.agg_revenue_to_first_day_month,
m.given_month_revenue_in_gbp,
m.previous_1_month_revenue_in_gbp,
@ -358,8 +358,8 @@ select
gsc.previous_2_month_first_day_month,
gsc.previous_12_month_first_day_month,
gsc.previous_13_month_first_day_month,
gsc.aggregated_revenue_from_first_day_month,
gsc.aggregated_revenue_to_first_day_month,
gsc.agg_revenue_from_first_day_month,
gsc.agg_revenue_to_first_day_month,
gsc.given_month_revenue_in_gbp,
gsc.previous_1_month_revenue_in_gbp,

View file

@ -6,104 +6,104 @@ previous year for each line & computing relative increment. --
with
created_bookings as (
select *
from {{ ref("int_kpis__aggregated_mtd_created_bookings") }}
from {{ ref("int_kpis__agg_mtd_created_bookings") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__aggregated_monthly_created_bookings") }}
from {{ ref("int_kpis__agg_monthly_created_bookings") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
check_out_bookings as (
select *
from {{ ref("int_kpis__aggregated_mtd_check_out_bookings") }}
from {{ ref("int_kpis__agg_mtd_check_out_bookings") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__aggregated_monthly_check_out_bookings") }}
from {{ ref("int_kpis__agg_monthly_check_out_bookings") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
cancelled_bookings as (
select *
from {{ ref("int_kpis__aggregated_mtd_cancelled_bookings") }}
from {{ ref("int_kpis__agg_mtd_cancelled_bookings") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__aggregated_monthly_cancelled_bookings") }}
from {{ ref("int_kpis__agg_monthly_cancelled_bookings") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
billable_bookings as (
select *
from {{ ref("int_kpis__aggregated_mtd_billable_bookings") }}
from {{ ref("int_kpis__agg_mtd_billable_bookings") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__aggregated_monthly_billable_bookings") }}
from {{ ref("int_kpis__agg_monthly_billable_bookings") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
created_guest_journeys as (
select *
from {{ ref("int_kpis__aggregated_mtd_created_guest_journeys") }}
from {{ ref("int_kpis__agg_mtd_created_guest_journeys") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__aggregated_monthly_created_guest_journeys") }}
from {{ ref("int_kpis__agg_monthly_created_guest_journeys") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
started_guest_journeys as (
select *
from {{ ref("int_kpis__aggregated_mtd_started_guest_journeys") }}
from {{ ref("int_kpis__agg_mtd_started_guest_journeys") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__aggregated_monthly_started_guest_journeys") }}
from {{ ref("int_kpis__agg_monthly_started_guest_journeys") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
completed_guest_journeys as (
select *
from {{ ref("int_kpis__aggregated_mtd_completed_guest_journeys") }}
from {{ ref("int_kpis__agg_mtd_completed_guest_journeys") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__aggregated_monthly_completed_guest_journeys") }}
from {{ ref("int_kpis__agg_monthly_completed_guest_journeys") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
),
guest_journeys_with_payment as (
select *
from {{ ref("int_kpis__aggregated_mtd_guest_journeys_with_payment") }}
from {{ ref("int_kpis__agg_mtd_guest_journeys_with_payment") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__aggregated_monthly_guest_journeys_with_payment") }}
from {{ ref("int_kpis__agg_monthly_guest_journeys_with_payment") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
@ -114,13 +114,13 @@ with
int_mtd_deal_metrics as (select * from {{ ref("int_mtd_deal_metrics") }}),
guest_payments as (
select *
from {{ ref("int_kpis__aggregated_mtd_guest_payments") }}
from {{ ref("int_kpis__agg_mtd_guest_payments") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
union all
select *
from {{ ref("int_kpis__aggregated_monthly_guest_payments") }}
from {{ ref("int_kpis__agg_monthly_guest_payments") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'

View file

@ -445,7 +445,7 @@ models:
Count of accumulated bookings created in a given month up to the
given date and per specified dimension.
- name: int_kpis__aggregated_monthly_created_bookings
- name: int_kpis__agg_monthly_created_bookings
description: |
This model computes the dimension aggregation for
Monthly Created Bookings.
@ -499,7 +499,7 @@ models:
data_type: bigint
description: The monthly created bookings for a given date, dimension and value.
- name: int_kpis__aggregated_mtd_created_bookings
- name: int_kpis__agg_mtd_created_bookings
description: |
This model computes the dimension aggregation for
Month-To-Date Created Bookings.
@ -749,7 +749,7 @@ models:
Count of accumulated guest journeys created in a given month up to the
given date and per specified dimension.
- name: int_kpis__aggregated_monthly_created_guest_journeys
- name: int_kpis__agg_monthly_created_guest_journeys
description: |
This model computes the dimension aggregation for
Monthly Created Guest Journeys.
@ -802,7 +802,7 @@ models:
data_type: bigint
description: The monthtly created guest journeys for a given date, dimension and value.
- name: int_kpis__aggregated_mtd_created_guest_journeys
- name: int_kpis__agg_mtd_created_guest_journeys
description: |
This model computes the dimension aggregation for
Month-To-Date Created Guest Journeys.
@ -1051,7 +1051,7 @@ models:
Count of accumulated guest journeys started in a given month up to the
given date and per specified dimension.
- name: int_kpis__aggregated_monthly_started_guest_journeys
- name: int_kpis__agg_monthly_started_guest_journeys
description: |
This model computes the dimension aggregation for
Monthly Started Guest Journeys.
@ -1104,7 +1104,7 @@ models:
data_type: bigint
description: The monthly started guest journeys for a given date, dimension and value.
- name: int_kpis__aggregated_mtd_started_guest_journeys
- name: int_kpis__agg_mtd_started_guest_journeys
description: |
This model computes the dimension aggregation for
Month-To-Date Started Guest Journeys.
@ -1353,7 +1353,7 @@ models:
Count of accumulated guest journeys completed in a given month up to the
given date and per specified dimension.
- name: int_kpis__aggregated_monthly_completed_guest_journeys
- name: int_kpis__agg_monthly_completed_guest_journeys
description: |
This model computes the dimension aggregation for
Monthly Completed Guest Journeys.
@ -1406,7 +1406,7 @@ models:
data_type: bigint
description: The monthly completed guest journeys for a given date, dimension and value.
- name: int_kpis__aggregated_mtd_completed_guest_journeys
- name: int_kpis__agg_mtd_completed_guest_journeys
description: |
This model computes the dimension aggregation for
Month-To-Date Completed Guest Journeys.
@ -1655,7 +1655,7 @@ models:
Count of accumulated guest journeys completed in a given month up to the
given date and per specified dimension.
- name: int_kpis__aggregated_monthly_guest_journeys_with_payment
- name: int_kpis__agg_monthly_guest_journeys_with_payment
description: |
This model computes the dimension aggregation for
Monthly Guest Journeys with Payment.
@ -1708,7 +1708,7 @@ models:
data_type: bigint
description: The monthly guest journeys with payment for a given date, dimension and value.
- name: int_kpis__aggregated_mtd_guest_journeys_with_payment
- name: int_kpis__agg_mtd_guest_journeys_with_payment
description: |
This model computes the dimension aggregation for
Month-To-Date Guest Journeys with Payment.
@ -2012,7 +2012,7 @@ models:
Sum of accumulated total payments paid by guests, without taxes,
in GBP in a given month up to the given date and per specified dimension.
- name: int_kpis__aggregated_monthly_guest_payments
- name: int_kpis__agg_monthly_guest_payments
description: |
This model computes the dimension aggregation for
Monthly Guest Payments.
@ -2091,7 +2091,7 @@ models:
The monthly total payments paid by guests, without taxes, in GBP
for a given range date, dimension and value.
- name: int_kpis__aggregated_mtd_guest_payments
- name: int_kpis__agg_mtd_guest_payments
description: |
This model computes the dimension aggregation for
Month-To-Date Guest Payments.
@ -2366,7 +2366,7 @@ models:
Count of accumulated bookings checked-out in a given month up to the
given date and per specified dimension.
- name: int_kpis__aggregated_monthly_check_out_bookings
- name: int_kpis__agg_monthly_check_out_bookings
description: |
This model computes the dimension aggregation for
Monthly Check-out Bookings.
@ -2419,7 +2419,7 @@ models:
data_type: bigint
description: The monthly checked-out bookings for a given date, dimension and value.
- name: int_kpis__aggregated_mtd_check_out_bookings
- name: int_kpis__agg_mtd_check_out_bookings
description: |
This model computes the dimension aggregation for
Month-To-Date Check-out Bookings.
@ -2668,7 +2668,7 @@ models:
Count of accumulated bookings billable in a given month up to the
given date and per specified dimension.
- name: int_kpis__aggregated_monthly_billable_bookings
- name: int_kpis__agg_monthly_billable_bookings
description: |
This model computes the dimension aggregation for
Monthly Billable Bookings.
@ -2721,7 +2721,7 @@ models:
data_type: bigint
description: The monthly billable bookings for a given date, dimension and value.
- name: int_kpis__aggregated_mtd_billable_bookings
- name: int_kpis__agg_mtd_billable_bookings
description: |
This model computes the dimension aggregation for
Month-To-Date Billable Bookings.
@ -2970,7 +2970,7 @@ models:
Count of accumulated bookings cancelled in a given month up to the
given date and per specified dimension.
- name: int_kpis__aggregated_monthly_cancelled_bookings
- name: int_kpis__agg_monthly_cancelled_bookings
description: |
This model computes the dimension aggregation for
Monthly Cancelled Bookings.
@ -3023,7 +3023,7 @@ models:
data_type: bigint
description: The monthly cancelled bookings for a given date, dimension and value.
- name: int_kpis__aggregated_mtd_cancelled_bookings
- name: int_kpis__agg_mtd_cancelled_bookings
description: |
This model computes the dimension aggregation for
Month-To-Date Cancelled Bookings.