data-dwh-dbt-project/models/intermediate/cross/int_mtd_aggregated_metrics.sql
Oriol Roqué Paniagua 3b75d9eefb Merged PR 2257: Expose guest revenue and guest journey payment metrics
This PR aims to expose the new metrics to the business KPIs report.
The new metrics exposed are, for the global and the by deal view:
- Guest Revenue
- Guest Revenue per Guest Journey Completed
- Guest Revenue per Guest Journey with Payment
- Guest Payments
- Guest Payments per Guest Journey Completed
- Guest Payments per Guest Journey with Payment
- Guest Journey with Payment
- Guest Journey Payment Rate

Changes:
- Silly change on the naming in the by deal view of `payment_rate_guest_journey` to be consistent with the global view.
- Silly change that I miss some GJ payment metric for the view by deal id.
- Added a new number format called `currency_gbp` - only for monetary metrics, available in the schema files
- Usual procedure to publish metrics: for global metrics, add them in the `int_mtd_aggregated_metrics`. I also changed the order of display.
- **Important**: to avoid displaying revenue figures until Xero invoicing is handled, I created a macro called `is_date_before_previous_month` that is called in the reporting equivalent models: `mtd_aggregated_metrics` in the where section and in the `monthly_aggregated_metrics_history_by_deal` as a case-when.

This should allow to expose all new metrics, and enable the publishing of a new update of the business kpis!

Related work items: #18107
2024-07-10 14:17:05 +00:00

259 lines
9.8 KiB
SQL

{% set metrics = [
{
"order_by": 1,
"metric": "Created Bookings",
"value": "created_bookings",
"previous_year_value": "previous_year_created_bookings",
"relative_increment": "relative_increment_created_bookings",
"number_format": "integer",
},
{
"order_by": 2,
"metric": "Cancelled Bookings",
"value": "cancelled_bookings",
"previous_year_value": "previous_year_cancelled_bookings",
"relative_increment": "relative_increment_cancelled_bookings",
"number_format": "integer",
},
{
"order_by": 3,
"metric": "Checkout Bookings",
"value": "check_out_bookings",
"previous_year_value": "previous_year_check_out_bookings",
"relative_increment": "relative_increment_check_out_bookings",
"number_format": "integer",
},
{
"order_by": 4,
"metric": "Guest Journey Created",
"value": "created_guest_journeys",
"previous_year_value": "previous_year_created_guest_journeys",
"relative_increment": "relative_increment_created_guest_journeys",
"number_format": "integer",
},
{
"order_by": 5,
"metric": "Guest Journey Started",
"value": "started_guest_journeys",
"previous_year_value": "previous_year_started_guest_journeys",
"relative_increment": "relative_increment_started_guest_journeys",
"number_format": "integer",
},
{
"order_by": 6,
"metric": "Guest Journey Completed",
"value": "completed_guest_journeys",
"previous_year_value": "previous_year_completed_guest_journeys",
"relative_increment": "relative_increment_completed_guest_journeys",
"number_format": "integer",
},
{
"order_by": 7,
"metric": "Guest Journey with Payment",
"value": "paid_guest_journeys",
"previous_year_value": "previous_year_paid_guest_journeys",
"relative_increment": "relative_increment_paid_guest_journeys",
"number_format": "integer",
},
{
"order_by": 8,
"metric": "New Deals",
"value": "new_deals",
"previous_year_value": "previous_year_new_deals",
"relative_increment": "relative_increment_new_deals",
"number_format": "integer",
},
{
"order_by": 9,
"metric": "First Time Booked Deals",
"value": "first_time_booked_deals",
"previous_year_value": "previous_year_first_time_booked_deals",
"relative_increment": "relative_increment_first_time_booked_deals",
"number_format": "integer",
},
{
"order_by": 10,
"metric": "Deals Booked in Month",
"value": "deals_booked_in_month",
"previous_year_value": "previous_year_deals_booked_in_month",
"relative_increment": "relative_increment_deals_booked_in_month",
"number_format": "integer",
},
{
"order_by": 11,
"metric": "Deals Booked in 6 Months",
"value": "deals_booked_in_6_months",
"previous_year_value": "previous_year_deals_booked_in_6_months",
"relative_increment": "relative_increment_deals_booked_in_6_months",
"number_format": "integer",
},
{
"order_by": 12,
"metric": "Deals Booked in 12 Months",
"value": "deals_booked_in_12_months",
"previous_year_value": "previous_year_deals_booked_in_12_months",
"relative_increment": "relative_increment_deals_booked_in_12_months",
"number_format": "integer",
},
{
"order_by": 13,
"metric": "Churning Deals",
"value": "churning_deals",
"previous_year_value": "previous_year_churning_deals",
"relative_increment": "relative_increment_churning_deals",
"number_format": "integer",
},
{
"order_by": 14,
"metric": "New Listings",
"value": "new_listings",
"previous_year_value": "previous_year_new_listings",
"relative_increment": "relative_increment_new_listings",
"number_format": "integer",
},
{
"order_by": 15,
"metric": "First Time Booked Listings",
"value": "first_time_booked_listings",
"previous_year_value": "previous_year_first_time_booked_listings",
"relative_increment": "relative_increment_first_time_booked_listings",
"number_format": "integer",
},
{
"order_by": 16,
"metric": "Listings Booked in Month",
"value": "listings_booked_in_month",
"previous_year_value": "previous_year_listings_booked_in_month",
"relative_increment": "relative_increment_listings_booked_in_month",
"number_format": "integer",
},
{
"order_by": 17,
"metric": "Listings Booked in 6 Months",
"value": "listings_booked_in_6_months",
"previous_year_value": "previous_year_listings_booked_in_6_months",
"relative_increment": "relative_increment_listings_booked_in_6_months",
"number_format": "integer",
},
{
"order_by": 18,
"metric": "Listings Booked in 12 Months",
"value": "listings_booked_in_12_months",
"previous_year_value": "previous_year_listings_booked_in_12_months",
"relative_increment": "relative_increment_listings_booked_in_12_months",
"number_format": "integer",
},
{
"order_by": 19,
"metric": "Churning Listings",
"value": "churning_listings",
"previous_year_value": "previous_year_churning_listings",
"relative_increment": "relative_increment_churning_listings",
"number_format": "integer",
},
{
"order_by": 100,
"metric": "Guest Journey Start Rate",
"value": "start_rate_guest_journey",
"previous_year_value": "previous_year_start_rate_guest_journey",
"relative_increment": "relative_increment_start_rate_guest_journey",
"number_format": "percentage",
},
{
"order_by": 101,
"metric": "Guest Journey Completion Rate",
"value": "completion_rate_guest_journey",
"previous_year_value": "previous_year_completion_rate_guest_journey",
"relative_increment": "relative_increment_completion_rate_guest_journey",
"number_format": "percentage",
},
{
"order_by": 102,
"metric": "Guest Journey Incompletion Rate",
"value": "incompletion_rate_guest_journey",
"previous_year_value": "previous_year_incompletion_rate_guest_journey",
"relative_increment": "relative_increment_incompletion_rate_guest_journey",
"number_format": "percentage",
},
{
"order_by": 103,
"metric": "Guest Journey Payment Rate",
"value": "payment_rate_guest_journey",
"previous_year_value": "previous_year_payment_rate_guest_journey",
"relative_increment": "relative_increment_payment_rate_guest_journey",
"number_format": "percentage",
},
{
"order_by": 200,
"metric": "Guest Payments (GBP)",
"value": "total_guest_payments_in_gbp",
"previous_year_value": "previous_year_total_guest_payments_in_gbp",
"relative_increment": "relative_increment_total_guest_payments_in_gbp",
"number_format": "currency_gbp",
},
{
"order_by": 201,
"metric": "Guest Payments per Guest Journey Completed (GBP)",
"value": "guest_payments_per_completed_guest_journey",
"previous_year_value": "previous_year_guest_payments_per_completed_guest_journey",
"relative_increment": "relative_increment_guest_payments_per_completed_guest_journey",
"number_format": "currency_gbp",
},
{
"order_by": 202,
"metric": "Guest Payments per Guest Journey with Payment (GBP)",
"value": "guest_payments_per_paid_guest_journey",
"previous_year_value": "previous_year_guest_payments_per_paid_guest_journey",
"relative_increment": "relative_increment_guest_payments_per_paid_guest_journey",
"number_format": "currency_gbp",
},
{
"order_by": 203,
"metric": "Guest Revenue (GBP)",
"value": "total_guest_revenue_in_gbp",
"previous_year_value": "previous_year_total_guest_revenue_in_gbp",
"relative_increment": "relative_increment_total_guest_revenue_in_gbp",
"number_format": "currency_gbp",
},
{
"order_by": 204,
"metric": "Guest Revenue per Guest Journey Completed (GBP)",
"value": "guest_revenue_per_completed_guest_journey",
"previous_year_value": "previous_year_guest_revenue_per_completed_guest_journey",
"relative_increment": "relative_increment_guest_revenue_per_completed_guest_journey",
"number_format": "currency_gbp",
},
{
"order_by": 205,
"metric": "Guest Revenue per Guest Journey with Payment (GBP)",
"value": "guest_revenue_per_paid_guest_journey",
"previous_year_value": "previous_year_guest_revenue_per_paid_guest_journey",
"relative_increment": "relative_increment_guest_revenue_per_paid_guest_journey",
"number_format": "currency_gbp",
}
] %}
with
int_mtd_vs_previous_year_metrics as (
select * from {{ ref("int_mtd_vs_previous_year_metrics") }}
)
{% for metric in metrics %}
select
year,
month,
day,
is_end_of_month,
is_current_month,
date,
previous_year_date,
{{ metric.order_by }} as order_by,
-- quotation marks added because text format
'{{ metric.number_format }}' as number_format,
'{{ metric.metric }}' as metric,
{{ metric.value }} as value,
{{ metric.previous_year_value }} as previous_year_value,
{{ metric.relative_increment }} as relative_increment
from int_mtd_vs_previous_year_metrics
{% if not loop.last %}
union all
{% endif %}
{% endfor %}