2025-01-03 08:07:16 +00:00
|
|
|
/*
|
|
|
|
|
This macro calculates the aggregation of a metric over a partition of a column,
|
|
|
|
|
ordered by another column, with a window of x and y preceeding rows.
|
|
|
|
|
|
|
|
|
|
It's designed to be placed within a SELECT statement.
|
2025-01-07 15:22:30 +00:00
|
|
|
|
|
|
|
|
If include_all_history is True, then X is ignored.
|
2025-01-03 08:07:16 +00:00
|
|
|
*/
|
|
|
|
|
{% macro calculate_aggregation_between_preceeding_x_and_y(
|
|
|
|
|
metric,
|
|
|
|
|
aggregation="sum",
|
|
|
|
|
partition_by="id_deal",
|
|
|
|
|
order_by="date",
|
|
|
|
|
x=12,
|
2025-01-07 15:22:30 +00:00
|
|
|
y=1,
|
|
|
|
|
include_all_history=False
|
2025-01-03 08:07:16 +00:00
|
|
|
) %}
|
|
|
|
|
{{ aggregation }} ({{ metric }}) over (
|
|
|
|
|
partition by {{ partition_by }}
|
2025-01-07 15:22:30 +00:00
|
|
|
order by
|
|
|
|
|
{{ order_by }} rows between
|
|
|
|
|
{% if include_all_history %}
|
|
|
|
|
unbounded preceding
|
|
|
|
|
{% else %}
|
|
|
|
|
{{ x }} preceding
|
|
|
|
|
{% endif %}
|
|
|
|
|
and {{ y }} preceding
|
2025-01-03 08:07:16 +00:00
|
|
|
) as {{ aggregation }}_{{ metric }}
|
|
|
|
|
{% endmacro %}
|