Aggregated model for guest kpi metrics
This commit is contained in:
parent
961b5312b2
commit
07ffb14e9c
2 changed files with 81 additions and 250 deletions
|
|
@ -12,6 +12,7 @@
|
||||||
"checkin_cover_fees_in_gbp",
|
"checkin_cover_fees_in_gbp",
|
||||||
"total_guest_payments_in_gbp",
|
"total_guest_payments_in_gbp",
|
||||||
) %}
|
) %}
|
||||||
|
|
||||||
with
|
with
|
||||||
int_kpis__product_guest_daily_metrics as (
|
int_kpis__product_guest_daily_metrics as (
|
||||||
select
|
select
|
||||||
|
|
@ -44,6 +45,7 @@ with
|
||||||
{{ yesterday }} - interval '1 month' as pm_current_date,
|
{{ yesterday }} - interval '1 month' as pm_current_date,
|
||||||
{{ yesterday }} - interval '1 week' as pw_current_date,
|
{{ yesterday }} - interval '1 week' as pw_current_date,
|
||||||
extract(day from {{ yesterday }}) as current_day_of_month
|
extract(day from {{ yesterday }}) as current_day_of_month
|
||||||
|
|
||||||
),
|
),
|
||||||
aggregated_metrics as (
|
aggregated_metrics as (
|
||||||
{% for metric in metric_names %}
|
{% for metric in metric_names %}
|
||||||
|
|
@ -136,256 +138,6 @@ with
|
||||||
union all
|
union all
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
),
|
|
||||||
metric_values as (
|
|
||||||
select
|
|
||||||
date_day,
|
|
||||||
has_payment,
|
|
||||||
has_id_check,
|
|
||||||
main_billing_country_iso_3_per_deal,
|
|
||||||
created_guest_journeys_not_cancelled,
|
|
||||||
completed_guest_journeys_not_cancelled,
|
|
||||||
-- Calculate the relevant sums for different timeframes
|
|
||||||
sum(
|
|
||||||
case
|
|
||||||
when date_day between dr.current_year_start and {{ yesterday }}
|
|
||||||
then created_guest_journeys_not_cancelled
|
|
||||||
end
|
|
||||||
) as ytd_created,
|
|
||||||
sum(
|
|
||||||
case
|
|
||||||
when date_day between dr.current_year_start and {{ yesterday }}
|
|
||||||
then completed_guest_journeys_not_cancelled
|
|
||||||
end
|
|
||||||
) as ytd_completed,
|
|
||||||
sum(
|
|
||||||
case
|
|
||||||
when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
then created_guest_journeys_not_cancelled
|
|
||||||
end
|
|
||||||
) as py_created,
|
|
||||||
sum(
|
|
||||||
case
|
|
||||||
when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
then completed_guest_journeys_not_cancelled
|
|
||||||
end
|
|
||||||
) as py_completed,
|
|
||||||
sum(
|
|
||||||
case
|
|
||||||
when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
then created_guest_journeys_not_cancelled
|
|
||||||
end
|
|
||||||
) as pp_created,
|
|
||||||
sum(
|
|
||||||
case
|
|
||||||
when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
then completed_guest_journeys_not_cancelled
|
|
||||||
end
|
|
||||||
) as pp_completed
|
|
||||||
from int_kpis__product_guest_daily_metrics dm
|
|
||||||
cross join date_ranges dr
|
|
||||||
where extract(day from date_day) <= dr.current_day_of_month
|
|
||||||
group by
|
|
||||||
date_day, has_payment, has_id_check, main_billing_country_iso_3_per_deal
|
|
||||||
),
|
|
||||||
calculated_metrics as (
|
|
||||||
select
|
|
||||||
'guest_journey_conversion_rate' as metric,
|
|
||||||
has_payment,
|
|
||||||
has_id_check,
|
|
||||||
main_billing_country_iso_3_per_deal,
|
|
||||||
'YTD' as timeframe,
|
|
||||||
case
|
|
||||||
when ytd_created = 0 then null else ytd_completed / ytd_created
|
|
||||||
end as current_value,
|
|
||||||
case
|
|
||||||
when py_created = 0 then null else py_completed / py_created
|
|
||||||
end as py_value,
|
|
||||||
case
|
|
||||||
when pp_created = 0 then null else pp_completed / pp_created
|
|
||||||
end as pp_value
|
|
||||||
from metric_values
|
|
||||||
)
|
)
|
||||||
-- select
|
|
||||||
-- 'guest_journey_conversion_rate' as metric,
|
|
||||||
-- has_payment,
|
|
||||||
-- has_id_check,
|
|
||||||
-- main_billing_country_iso_3_per_deal,
|
|
||||||
-- 'YTD' as timeframe,
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- date_day
|
|
||||||
-- between dr.current_year_start and {{ yesterday }}
|
|
||||||
-- then created_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- )
|
|
||||||
-- = 0
|
|
||||||
-- then null
|
|
||||||
-- else
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- date_day
|
|
||||||
-- between dr.current_year_start and {{ yesterday }}
|
|
||||||
-- then completed_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- ) / sum(
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- date_day
|
|
||||||
-- between dr.current_year_start and {{ yesterday }}
|
|
||||||
-- then created_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- )
|
|
||||||
-- end as current_value,
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- date_day
|
|
||||||
-- between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then created_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- )
|
|
||||||
-- = 0
|
|
||||||
-- then null
|
|
||||||
-- else
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- date_day
|
|
||||||
-- between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then completed_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- ) / sum(
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- date_day
|
|
||||||
-- between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then created_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- ) as py_value,
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- date_day
|
|
||||||
-- between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then created_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- )
|
|
||||||
-- = 0
|
|
||||||
-- then null
|
|
||||||
-- else
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- date_day
|
|
||||||
-- between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then completed_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- ) / sum(
|
|
||||||
-- case
|
|
||||||
-- when
|
|
||||||
-- date_day
|
|
||||||
-- between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then created_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- ) as pp_value
|
|
||||||
-- from int_kpis__product_guest_daily_metrics dm, date_ranges dr
|
|
||||||
-- where extract(day from date_day) <= dr.current_day_of_month
|
|
||||||
-- group by metric, has_payment, has_id_check, main_billing_country_iso_3_per_deal
|
|
||||||
-- union all
|
|
||||||
-- select
|
|
||||||
-- 'guest_revenue_per_guest_journey_created' as metric,
|
|
||||||
-- has_payment,
|
|
||||||
-- has_id_check,
|
|
||||||
-- main_billing_country_iso_3_per_deal,
|
|
||||||
-- 'YTD' as timeframe,
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.current_year_start and {{ yesterday }}
|
|
||||||
-- then total_guest_payments_in_gbp
|
|
||||||
-- end
|
|
||||||
-- ) / sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.current_year_start and {{ yesterday }}
|
|
||||||
-- then created_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- ) as current_value,
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then total_guest_payments_in_gbp
|
|
||||||
-- end
|
|
||||||
-- ) / sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then completed_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- ) as py_value,
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then total_guest_payments_in_gbp
|
|
||||||
-- end
|
|
||||||
-- ) / sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then completed_guest_journeys_not_cancelled
|
|
||||||
-- end
|
|
||||||
-- ) as pp_value
|
|
||||||
-- from int_kpis__product_guest_daily_metrics dm, date_ranges dr
|
|
||||||
-- where extract(day from date_day) <= dr.current_day_of_month
|
|
||||||
-- group by metric, has_payment, has_id_check, main_billing_country_iso_3_per_deal
|
|
||||||
-- union all
|
|
||||||
-- select
|
|
||||||
-- 'csat_score' as metric,
|
|
||||||
-- has_payment,
|
|
||||||
-- has_id_check,
|
|
||||||
-- main_billing_country_iso_3_per_deal,
|
|
||||||
-- 'YTD' as timeframe,
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.current_year_start and {{ yesterday }}
|
|
||||||
-- then total_csat_score_count * average_csat_score
|
|
||||||
-- end
|
|
||||||
-- ) / sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.current_year_start and {{ yesterday }}
|
|
||||||
-- then total_csat_score_count
|
|
||||||
-- end
|
|
||||||
-- ) as current_value,
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then total_csat_score_count * average_csat_score
|
|
||||||
-- end
|
|
||||||
-- ) / sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then total_csat_score_count
|
|
||||||
-- end
|
|
||||||
-- ) as py_value,
|
|
||||||
-- sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then total_csat_score_count * average_csat_score
|
|
||||||
-- end
|
|
||||||
-- ) / sum(
|
|
||||||
-- case
|
|
||||||
-- when date_day between dr.py_year_start and dr.py_current_date
|
|
||||||
-- then total_csat_score_count
|
|
||||||
-- end
|
|
||||||
-- ) as pp_value
|
|
||||||
-- from int_kpis__product_guest_daily_metrics dm, date_ranges dr
|
|
||||||
-- where extract(day from date_day) <= dr.current_day_of_month
|
|
||||||
-- group by metric, has_payment, has_id_check, main_billing_country_iso_3_per_deal
|
|
||||||
-- )
|
|
||||||
select *
|
select *
|
||||||
from aggregated_metrics
|
from aggregated_metrics
|
||||||
|
|
|
||||||
|
|
@ -5287,6 +5287,85 @@ models:
|
||||||
Sum of total payments paid by guests, excluding taxes, in GBP
|
Sum of total payments paid by guests, excluding taxes, in GBP
|
||||||
on the same date in the previous year, segmented by the specified dimension.
|
on the same date in the previous year, segmented by the specified dimension.
|
||||||
|
|
||||||
|
- name: int_kpis__product_guest_agg_metrics
|
||||||
|
description:
|
||||||
|
This model aggregates multiple metrics on a Year-to-date, Month-to-date or
|
||||||
|
Week-to-date basis. This model changes the display format of the model
|
||||||
|
int_kpis__product_guest_daily_metrics pivoting the metrics columns and
|
||||||
|
adding a timeframe dimension.
|
||||||
|
columns:
|
||||||
|
- name: metric
|
||||||
|
data_type: text
|
||||||
|
description: Name of the business metric
|
||||||
|
|
||||||
|
- name: has_payment
|
||||||
|
data_type: string
|
||||||
|
description: Has there been any guest payments on the guest journey.
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- accepted_values:
|
||||||
|
values:
|
||||||
|
- W/O Payment
|
||||||
|
- With Payment
|
||||||
|
|
||||||
|
- name: has_id_check
|
||||||
|
data_type: string
|
||||||
|
description: Does the verification in the guest journey
|
||||||
|
includes Government Id Check for the bookings.
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- accepted_values:
|
||||||
|
values:
|
||||||
|
- W/O Id Check
|
||||||
|
- With Id Check
|
||||||
|
|
||||||
|
- name: main_billing_country_iso_3_per_deal
|
||||||
|
data_type: string
|
||||||
|
description: |
|
||||||
|
Main billing country of the host aggregated at Deal level.
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
|
||||||
|
- name: timeframe
|
||||||
|
data_type: text
|
||||||
|
description: |
|
||||||
|
Timeframe considered for the aggregation, it could be Year-to-date,
|
||||||
|
Month-to-date or Week-to-date
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- accepted_values:
|
||||||
|
values:
|
||||||
|
- YTD
|
||||||
|
- MTD
|
||||||
|
- WTD
|
||||||
|
|
||||||
|
- name: current_value
|
||||||
|
data_type: numeric
|
||||||
|
description: |
|
||||||
|
Numeric value (integer or decimal) that corresponds to the timeframe
|
||||||
|
computation of the metric at the current date.
|
||||||
|
For example if the current date is 27/11/2024 and the timeframe is MTD,
|
||||||
|
then this value would correspond to the computation of the metric for
|
||||||
|
the dates between 01/11/2024 and 27/11/2024.
|
||||||
|
|
||||||
|
- name: py_value
|
||||||
|
data_type: numeric
|
||||||
|
description: |
|
||||||
|
Numeric value (integer or decimal) that corresponds to the timeframe
|
||||||
|
computation of the metric at the current date but on the previous year.
|
||||||
|
For example if the current date is 27/11/2024 and the timeframe is MTD,
|
||||||
|
then this value would correspond to the computation of the metric for
|
||||||
|
the dates between 01/11/2023 and 27/11/2023.
|
||||||
|
|
||||||
|
- name: pp_value
|
||||||
|
data_type: numeric
|
||||||
|
description: |
|
||||||
|
Numeric value (integer or decimal) that corresponds to the timeframe
|
||||||
|
computation of the metric at the current date but on the previous period.
|
||||||
|
For example if the current date is 27/11/2024 and the timeframe is MTD,
|
||||||
|
then this value would correspond to the computation of the metric for
|
||||||
|
the dates between 01/10/2024 and 27/10/2024.
|
||||||
|
|
||||||
- name: int_kpis__metric_daily_new_dash_created_services
|
- name: int_kpis__metric_daily_new_dash_created_services
|
||||||
description: |
|
description: |
|
||||||
This model computes the Daily Created Services at the deepest granularity.
|
This model computes the Daily Created Services at the deepest granularity.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue