Relative increments with sign

This commit is contained in:
uri 2025-02-25 12:30:23 +01:00
parent fdec616fe6
commit f5718ded4d
4 changed files with 159 additions and 27 deletions

View file

@ -8,6 +8,7 @@
"current_YTD": "current_ytd_total_revenue_in_gbp", "current_YTD": "current_ytd_total_revenue_in_gbp",
"previous_YTD": "previous_ytd_total_revenue_in_gbp", "previous_YTD": "previous_ytd_total_revenue_in_gbp",
"display_exclusion": "INVOICING", "display_exclusion": "INVOICING",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 2, "id_metric": 2,
@ -18,6 +19,7 @@
"current_YTD": "current_ytd_revenue_retained_post_resolutions_in_gbp", "current_YTD": "current_ytd_revenue_retained_post_resolutions_in_gbp",
"previous_YTD": "previous_ytd_revenue_retained_post_resolutions_in_gbp", "previous_YTD": "previous_ytd_revenue_retained_post_resolutions_in_gbp",
"display_exclusion": "INVOICING", "display_exclusion": "INVOICING",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 3, "id_metric": 3,
@ -28,6 +30,7 @@
"current_YTD": "current_ytd_total_guest_payments_in_gbp", "current_YTD": "current_ytd_total_guest_payments_in_gbp",
"previous_YTD": "previous_ytd_total_guest_payments_in_gbp", "previous_YTD": "previous_ytd_total_guest_payments_in_gbp",
"display_exclusion": "NONE", "display_exclusion": "NONE",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 4, "id_metric": 4,
@ -38,6 +41,7 @@
"current_YTD": "current_ytd_xero_operator_net_fees_in_gbp", "current_YTD": "current_ytd_xero_operator_net_fees_in_gbp",
"previous_YTD": "previous_ytd_xero_operator_net_fees_in_gbp", "previous_YTD": "previous_ytd_xero_operator_net_fees_in_gbp",
"display_exclusion": "INVOICING", "display_exclusion": "INVOICING",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 5, "id_metric": 5,
@ -48,6 +52,7 @@
"current_YTD": "current_ytd_xero_apis_net_fees_in_gbp", "current_YTD": "current_ytd_xero_apis_net_fees_in_gbp",
"previous_YTD": "previous_ytd_xero_apis_net_fees_in_gbp", "previous_YTD": "previous_ytd_xero_apis_net_fees_in_gbp",
"display_exclusion": "INVOICING", "display_exclusion": "INVOICING",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 6, "id_metric": 6,
@ -58,6 +63,7 @@
"current_YTD": "current_ytd_billable_bookings", "current_YTD": "current_ytd_billable_bookings",
"previous_YTD": "previous_ytd_billable_bookings", "previous_YTD": "previous_ytd_billable_bookings",
"display_exclusion": "NONE", "display_exclusion": "NONE",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 7, "id_metric": 7,
@ -68,6 +74,7 @@
"current_YTD": "current_ytd_live_deals", "current_YTD": "current_ytd_live_deals",
"previous_YTD": "previous_ytd_live_deals", "previous_YTD": "previous_ytd_live_deals",
"display_exclusion": "NONE", "display_exclusion": "NONE",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 8, "id_metric": 8,
@ -78,6 +85,7 @@
"current_YTD": "current_ytd_new_deals", "current_YTD": "current_ytd_new_deals",
"previous_YTD": "previous_ytd_new_deals", "previous_YTD": "previous_ytd_new_deals",
"display_exclusion": "NONE", "display_exclusion": "NONE",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 9, "id_metric": 9,
@ -88,6 +96,7 @@
"current_YTD": "current_ytd_churning_deals", "current_YTD": "current_ytd_churning_deals",
"previous_YTD": "previous_ytd_churning_deals", "previous_YTD": "previous_ytd_churning_deals",
"display_exclusion": "NONE", "display_exclusion": "NONE",
"increment_sign_format": "NEGATIVE",
}, },
{ {
"id_metric": 10, "id_metric": 10,
@ -98,6 +107,7 @@
"current_YTD": "current_ytd_waiver_payout_rate", "current_YTD": "current_ytd_waiver_payout_rate",
"previous_YTD": "previous_ytd_waiver_payout_rate", "previous_YTD": "previous_ytd_waiver_payout_rate",
"display_exclusion": "INVOICING", "display_exclusion": "INVOICING",
"increment_sign_format": "NEGATIVE",
}, },
{ {
"id_metric": 11, "id_metric": 11,
@ -108,6 +118,7 @@
"current_YTD": "current_ytd_resolutions_payout_rate", "current_YTD": "current_ytd_resolutions_payout_rate",
"previous_YTD": "previous_ytd_resolutions_payout_rate", "previous_YTD": "previous_ytd_resolutions_payout_rate",
"display_exclusion": "INVOICING", "display_exclusion": "INVOICING",
"increment_sign_format": "NEGATIVE",
}, },
{ {
"id_metric": 12, "id_metric": 12,
@ -118,6 +129,7 @@
"current_YTD": "current_ytd_operator_revenue_per_billable_booking", "current_YTD": "current_ytd_operator_revenue_per_billable_booking",
"previous_YTD": "previous_ytd_operator_revenue_per_billable_booking", "previous_YTD": "previous_ytd_operator_revenue_per_billable_booking",
"display_exclusion": "INVOICING", "display_exclusion": "INVOICING",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 13, "id_metric": 13,
@ -128,6 +140,7 @@
"current_YTD": "current_ytd_waiver_revenue_per_billable_booking", "current_YTD": "current_ytd_waiver_revenue_per_billable_booking",
"previous_YTD": "previous_ytd_waiver_revenue_per_billable_booking", "previous_YTD": "previous_ytd_waiver_revenue_per_billable_booking",
"display_exclusion": "NONE", "display_exclusion": "NONE",
"increment_sign_format": "POSITIVE",
}, },
{ {
"id_metric": 14, "id_metric": 14,
@ -138,6 +151,7 @@
"current_YTD": "-1*current_ytd_xero_waiver_paid_back_to_host_in_gbp", "current_YTD": "-1*current_ytd_xero_waiver_paid_back_to_host_in_gbp",
"previous_YTD": "-1*previous_ytd_xero_waiver_paid_back_to_host_in_gbp", "previous_YTD": "-1*previous_ytd_xero_waiver_paid_back_to_host_in_gbp",
"display_exclusion": "INVOICING", "display_exclusion": "INVOICING",
"increment_sign_format": "NEGATIVE",
}, },
{ {
"id_metric": 15, "id_metric": 15,
@ -148,6 +162,7 @@
"current_YTD": "-1*current_ytd_xero_host_resolution_amount_paid_in_gbp", "current_YTD": "-1*current_ytd_xero_host_resolution_amount_paid_in_gbp",
"previous_YTD": "-1*previous_ytd_xero_host_resolution_amount_paid_in_gbp", "previous_YTD": "-1*previous_ytd_xero_host_resolution_amount_paid_in_gbp",
"display_exclusion": "INVOICING", "display_exclusion": "INVOICING",
"increment_sign_format": "NEGATIVE",
}, },
{ {
"id_metric": 16, "id_metric": 16,
@ -158,6 +173,7 @@
"current_YTD": "current_ytd_total_revenue_churn_rate", "current_YTD": "current_ytd_total_revenue_churn_rate",
"previous_YTD": "previous_ytd_total_revenue_churn_rate", "previous_YTD": "previous_ytd_total_revenue_churn_rate",
"display_exclusion": "ONGOING_MONTH", "display_exclusion": "ONGOING_MONTH",
"increment_sign_format": "NEGATIVE",
}, },
{ {
"id_metric": 17, "id_metric": 17,
@ -168,6 +184,7 @@
"current_YTD": "current_ytd_onboarding_mrr", "current_YTD": "current_ytd_onboarding_mrr",
"previous_YTD": "previous_ytd_onboarding_mrr", "previous_YTD": "previous_ytd_onboarding_mrr",
"display_exclusion": "ONGOING_MONTH", "display_exclusion": "ONGOING_MONTH",
"increment_sign_format": "POSITIVE",
}, },
] %} ] %}
with with
@ -190,6 +207,7 @@ with
-- quotation marks added because text format -- quotation marks added because text format
'{{ metric.name }}' as metric_name, '{{ metric.name }}' as metric_name,
'{{ metric.display_exclusion }}' as display_exclusion, '{{ metric.display_exclusion }}' as display_exclusion,
'{{ metric.increment_sign_format }}' as increment_sign_format,
{{ metric.current_month_MTD }} as current_month_mtd, {{ metric.current_month_MTD }} as current_month_mtd,
{{ metric.previous_month_EOM }} as previous_month_eom, {{ metric.previous_month_EOM }} as previous_month_eom,
{{ metric.previous_year_MTD }} as previous_year_mtd, {{ metric.previous_year_MTD }} as previous_year_mtd,
@ -216,30 +234,63 @@ with
union all union all
{% endif %} {% endif %}
{% endfor %} {% endfor %}
),
metrics_with_targets as (
select
metrics.*,
-- EOM target --
targets.target_eom_value as target_eom_value,
metrics.current_month_mtd
- targets.target_eom_value as diff_current_month_mtd_vs_eom_target,
metrics.current_month_mtd / nullif(targets.target_eom_value, 0)
- 1 as rel_diff_current_month_mtd_vs_eom_target,
-- YTD target --
targets.target_ytd_value as target_ytd_value,
metrics.current_year_ytd
- targets.target_ytd_value as diff_current_ytd_vs_ytd_target,
metrics.current_year_ytd / nullif(targets.target_ytd_value, 0)
- 1 as rel_diff_current_ytd_vs_ytd_target,
-- EOFY target --
targets.target_eofy_value as target_eofy_value,
metrics.current_year_ytd
- targets.target_eofy_value as diff_current_ytd_vs_eofy_target,
metrics.current_year_ytd / nullif(
targets.target_eofy_value, 0
) as achievement_rate_current_ytd_vs_eofy_target
from main_metrics_aggregation as metrics
left join
stg_seed__main_metrics_targets as targets
on metrics.id_metric = targets.id_metric
and date_trunc('month', metrics.date)
= date_trunc('month', targets.target_date)
) )
select select
metrics.*, metrics_with_targets.*,
-- EOM target -- -- Add sign to relative differences --
targets.target_eom_value as target_eom_value, case
metrics.current_month_mtd when increment_sign_format = 'NEGATIVE'
- targets.target_eom_value as diff_current_month_mtd_vs_eom_target, then rel_diff_current_month_mtd_vs_previous_month_eom * -1
metrics.current_month_mtd / nullif(targets.target_eom_value, 0) else rel_diff_current_month_mtd_vs_previous_month_eom
- 1 as rel_diff_current_month_mtd_vs_eom_target, end as rel_diff_with_sign_current_month_mtd_vs_previous_month_eom,
-- YTD target -- case
targets.target_ytd_value as target_ytd_value, when increment_sign_format = 'NEGATIVE'
metrics.current_year_ytd then rel_diff_current_month_mtd_vs_previous_year_mtd * -1
- targets.target_ytd_value as diff_current_ytd_vs_ytd_target, else rel_diff_current_month_mtd_vs_previous_year_mtd
metrics.current_year_ytd / nullif(targets.target_ytd_value, 0) end as rel_diff_with_sign_current_month_mtd_vs_previous_year_mtd,
- 1 as rel_diff_current_ytd_vs_ytd_target, case
-- EOFY target -- when increment_sign_format = 'NEGATIVE'
targets.target_eofy_value as target_eofy_value, then rel_diff_current_ytd_vs_previous_ytd * -1
metrics.current_year_ytd else rel_diff_current_ytd_vs_previous_ytd
- targets.target_eofy_value as diff_current_ytd_vs_eofy_target, end as rel_diff_with_sign_current_ytd_vs_previous_ytd,
metrics.current_year_ytd / nullif( case
targets.target_eofy_value, 0 when increment_sign_format = 'NEGATIVE'
) as achievement_rate_current_ytd_vs_eofy_target then rel_diff_current_month_mtd_vs_eom_target * -1
from main_metrics_aggregation as metrics else rel_diff_current_month_mtd_vs_eom_target
left join end as rel_diff_with_sign_current_month_mtd_vs_eom_target,
stg_seed__main_metrics_targets as targets case
on metrics.id_metric = targets.id_metric when increment_sign_format = 'NEGATIVE'
and date_trunc('month', metrics.date) = date_trunc('month', targets.target_date) then rel_diff_current_ytd_vs_ytd_target * -1
else rel_diff_current_ytd_vs_ytd_target
end as rel_diff_with_sign_current_ytd_vs_ytd_target
from metrics_with_targets

View file

@ -2664,3 +2664,38 @@ models:
description: | description: |
Achievement rate between the current year YTD and the EOFY target. It can be null Achievement rate between the current year YTD and the EOFY target. It can be null
if the target is not available. if the target is not available.
- name: rel_diff_with_sign_current_month_mtd_vs_previous_month_eom
data_type: numeric
description: |
Relative difference between the current month MTD and the previous month EOM,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.
- name: rel_diff_with_sign_current_month_mtd_vs_previous_year_mtd
data_type: numeric
description: |
Relative difference between the current month MTD and the previous year MTD,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.
- name: rel_diff_with_sign_current_ytd_vs_previous_ytd
data_type: numeric
description: |
Relative difference between the current year YTD and the previous year YTD,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.
- name: rel_diff_with_sign_current_month_mtd_vs_eom_target
data_type: numeric
description: |
Relative difference between the current month MTD and the EOM target,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.
- name: rel_diff_with_sign_current_ytd_vs_ytd_target
data_type: numeric
description: |
Relative difference between the current year YTD and the YTD target,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.

View file

@ -2131,3 +2131,38 @@ models:
description: | description: |
Achievement rate between the current year YTD and the EOFY target. It can be null Achievement rate between the current year YTD and the EOFY target. It can be null
if the target is not available. if the target is not available.
- name: rel_diff_with_sign_current_month_mtd_vs_previous_month_eom
data_type: numeric
description: |
Relative difference between the current month MTD and the previous month EOM,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.
- name: rel_diff_with_sign_current_month_mtd_vs_previous_year_mtd
data_type: numeric
description: |
Relative difference between the current month MTD and the previous year MTD,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.
- name: rel_diff_with_sign_current_ytd_vs_previous_ytd
data_type: numeric
description: |
Relative difference between the current year YTD and the previous year YTD,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.
- name: rel_diff_with_sign_current_month_mtd_vs_eom_target
data_type: numeric
description: |
Relative difference between the current month MTD and the EOM target,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.
- name: rel_diff_with_sign_current_ytd_vs_ytd_target
data_type: numeric
description: |
Relative difference between the current year YTD and the YTD target,
with a sign to represent if the relative difference is good (positive) or bad
(negative) for our business.

View file

@ -3,7 +3,8 @@ with
select * from {{ ref("int_ytd_mtd_aggregated_main_metrics_overview") }} select * from {{ ref("int_ytd_mtd_aggregated_main_metrics_overview") }}
), ),
latest_dates_per_financial_year as ( latest_dates_per_financial_year as (
select dimension, financial_year, id_metric, max(date) as latest_available_date select
dimension, financial_year, id_metric, max(m.date) as latest_available_date
from int_ytd_mtd_aggregated_main_metrics_overview m from int_ytd_mtd_aggregated_main_metrics_overview m
where where
( (
@ -63,7 +64,17 @@ select
m.target_eofy_value as target_eofy_value, m.target_eofy_value as target_eofy_value,
m.diff_current_ytd_vs_eofy_target as diff_current_ytd_vs_eofy_target, m.diff_current_ytd_vs_eofy_target as diff_current_ytd_vs_eofy_target,
m.achievement_rate_current_ytd_vs_eofy_target m.achievement_rate_current_ytd_vs_eofy_target
as achievement_rate_current_ytd_vs_eofy_target as achievement_rate_current_ytd_vs_eofy_target,
m.rel_diff_with_sign_current_month_mtd_vs_previous_month_eom
as rel_diff_with_sign_current_month_mtd_vs_previous_month_eom,
m.rel_diff_with_sign_current_month_mtd_vs_previous_year_mtd
as rel_diff_with_sign_current_month_mtd_vs_previous_year_mtd,
m.rel_diff_with_sign_current_ytd_vs_previous_ytd
as rel_diff_with_sign_current_ytd_vs_previous_ytd,
m.rel_diff_with_sign_current_month_mtd_vs_eom_target
as rel_diff_with_sign_current_month_mtd_vs_eom_target,
m.rel_diff_with_sign_current_ytd_vs_ytd_target
as rel_diff_with_sign_current_ytd_vs_ytd_target
from int_ytd_mtd_aggregated_main_metrics_overview m from int_ytd_mtd_aggregated_main_metrics_overview m
inner join inner join
latest_dates_per_financial_year ld latest_dates_per_financial_year ld