Merged PR 4769: Refactors display exclusion in main metrics

# Description

I noticed this morning that after the name changes some exclusions have been messed up.

I think is about time we handle this properly. Following what we did for `ytd_mtd_aggregated_main_metrics_overview`, I apply the same logic: the metric display configuration is handled for each metric in the configuration rather than by some crazy-complex-name-logic.

I also took the opportunity to make Host Resolutions timely after a discussion with Chloe yesterday. Finance handles resolutions payments twice a week, and the "delay" in time is mostly coming from Resolutions accepting to pay someone vs. Finance handling the payment. In any case we're talking about a few days maximum difference, which I believe it's 1) process-related freshness, rather than data-related and 2) much better to have visibility in a timely manner rather than waiting for the 20th on next month.

# Checklist

- [X] The edited models and dependants run properly with production data.
- [X] The edited models are sufficiently documented.
- [X] The edited models contain PK tests, and I've ran and passed them.
- [ ] I have checked for DRY opportunities with other models and docs. **Logic is common among YTD and MTD models. At some moment this can be improved**
- [X] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

Related work items: #28560
This commit is contained in:
Oriol Roqué Paniagua 2025-03-21 09:40:20 +00:00
parent 240d6ec59e
commit 98c40d21d2
3 changed files with 99 additions and 42 deletions

View file

@ -50,52 +50,23 @@ select
previous_year_value as previous_year_value,
relative_increment as relative_increment,
relative_increment_with_sign_format as relative_increment_with_sign_format
from int_mtd_aggregated_metrics
/*
The following where condition is applied to avoid displaying revenue metrics
in the MTD for the current month and the previous month. The main reason is
that we have a time delay between when the guest does a payment vs. when we
invoice or credit hosts (Xero). Same applies for Host Resolutions.
This is specially tricky for the Host-takes-waiver revenue: guests payments
happen in a timely fashion, and we get all waiver money from the guests. Once
the month is finished, Finance will start to invoice hosts, and in this case,
all hosts that have the Host-takes-waiver need to be payed back the amount
coming from the guest.
Not having this filter would mean that, in the current month, the figures
displayed of guest revenue would be much larger than they actually will be
because we still need to pay back to the hosts these waivers.
For a more current-month evaluation, Guest Payments should be a good proxy
metric to follow.
*/
from int_mtd_aggregated_metrics m
where
(
(
-- Not show current + previous month if the metric depends on invoicing
-- cycle and it is before the 20th of the month, if it is the 20th of
-- the month or after, only exclude the current month.
(
lower(metric) like '%total revenue%'
or lower(metric) like '%resolutions%'
or lower(metric) like '%invoiced%'
or lower(metric) like '%retained%'
or lower(metric) like '%damage host%'
)
-- Not show current + previous month if the metric depends on
-- invoicing cycle and it is before the 20th of the month, if it
-- is the 20th of the month or after, only exclude the current
-- month.
display_exclusion = 'INVOICING'
and {{ is_date_before_20th_of_previous_month("date") }}
)
-- Keep all history for the rest of metrics
or not
(
lower(metric) like '%total revenue%'
or lower(metric) like '%resolutions%'
or lower(metric) like '%invoiced%'
or lower(metric) like '%retained%'
or lower(metric) like '%damage host%'
or (
-- Handle exclusion for Churn/MRR metrics: do not show them in the
-- current month.
display_exclusion = 'ONGOING_MONTH'
and date_trunc('month', m.date) < date_trunc('month', current_date)
)
)
-- If metric is Churn Rate or Expected MRR, do not show month in progress.
-- Unlike other revenue metrics, Expected MRR is calculated for the next month,
-- so it is not affected by the invoicing cycle.
and not (
(lower(metric) like '%churn rate%' or lower(metric) like '%mrr%')
and is_current_month = true
-- Keep all history for the rest of metrics
or display_exclusion = 'NONE'
)