changed exclusion rule for metrics depending on invoicing
This commit is contained in:
parent
142b5a526f
commit
396d19b549
2 changed files with 32 additions and 2 deletions
30
macros/is_date_before_previous_month_fixed_20.sql
Normal file
30
macros/is_date_before_previous_month_fixed_20.sql
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
This macro provides a boolean answer to the question:
|
||||||
|
- Is this date before the previous month?
|
||||||
|
- When the current day is before the 20th of the month, it returns:
|
||||||
|
- False for both the current and previous month.
|
||||||
|
- When the current day is the 20th or later, it returns:
|
||||||
|
- False only for the current month.
|
||||||
|
|
||||||
|
Inputs:
|
||||||
|
- date: the date to check
|
||||||
|
Output:
|
||||||
|
- boolean; true if the date is before the previous month
|
||||||
|
false if the date is within the current or previous month
|
||||||
|
(with special handling for the 20th or later of the month)
|
||||||
|
*/
|
||||||
|
{% macro is_date_before_previous_month_fixed_20(date) %}
|
||||||
|
(
|
||||||
|
case
|
||||||
|
-- If today is the 20th or later, only exclude current month
|
||||||
|
when extract(day from now()) >= 20
|
||||||
|
then
|
||||||
|
date_trunc('month', ({{ date }})::date)::date
|
||||||
|
< date_trunc('month', now())::date
|
||||||
|
-- If today is before the 20th, exclude both current and previous month
|
||||||
|
else
|
||||||
|
date_trunc('month', ({{ date }})::date)::date
|
||||||
|
< date_trunc('month', now() - interval '1 month')::date
|
||||||
|
end
|
||||||
|
)
|
||||||
|
{% endmacro %}
|
||||||
|
|
@ -70,7 +70,7 @@ where
|
||||||
or lower(metric) like '%retained%'
|
or lower(metric) like '%retained%'
|
||||||
or lower(metric) like '%damage host%'
|
or lower(metric) like '%damage host%'
|
||||||
)
|
)
|
||||||
and {{ is_date_before_previous_month("date") }}
|
and {{ is_date_before_previous_month_fixed_20("date") }}
|
||||||
)
|
)
|
||||||
-- Not show current month if the metric is Expected MRR, unlike other
|
-- Not show current month if the metric is Expected MRR, unlike other
|
||||||
-- revenue metrics, Expected MRR is calculated for the next month, so it is not
|
-- revenue metrics, Expected MRR is calculated for the next month, so it is not
|
||||||
|
|
@ -78,7 +78,7 @@ where
|
||||||
or not
|
or not
|
||||||
(
|
(
|
||||||
lower(metric) like '%mrr%'
|
lower(metric) like '%mrr%'
|
||||||
and date_trunc('month', m.date)::date = date_trunc('month', now())::date
|
and date_trunc('month', date)::date = date_trunc('month', now())::date
|
||||||
)
|
)
|
||||||
-- Keep all history for the rest of metrics
|
-- Keep all history for the rest of metrics
|
||||||
or not
|
or not
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue