Update rule for metric depends on invoicing
This commit is contained in:
parent
a208541e04
commit
1e37d04f72
2 changed files with 30 additions and 2 deletions
27
macros/is_date_before_20th_of_previous_month.sql
Normal file
27
macros/is_date_before_20th_of_previous_month.sql
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
This macro returns a boolean value for dates depending on the current day of the month
|
||||
|
||||
Logic:
|
||||
- If today is the 20th or later of the current month:
|
||||
- Returns **False** for all dates within the current month.
|
||||
- Returns **True** for dates before the current month.
|
||||
- If today is before the 20th:
|
||||
- Returns **False** for all dates within the current and previous month.
|
||||
- Returns **True** for dates before the previous month.
|
||||
|
||||
*/
|
||||
{% macro is_date_before_20th_of_previous_month(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 %}
|
||||
|
|
@ -62,7 +62,8 @@ where
|
|||
(
|
||||
(
|
||||
-- Not show current + previous month if the metric depends on invoicing
|
||||
-- cycle
|
||||
-- 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%'
|
||||
|
|
@ -71,7 +72,7 @@ where
|
|||
or lower(metric) like '%mrr%'
|
||||
or lower(metric) like '%damage host%'
|
||||
)
|
||||
and {{ is_date_before_previous_month("date") }}
|
||||
and {{ is_date_before_20th_of_previous_month("date") }}
|
||||
)
|
||||
-- Keep all history for the rest of metrics
|
||||
or not
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue