# Description Quick improvement to be able to report the same setup of metrics by considering all account history up to a certain date. It adds a new computation flow for this All History window. Note that I needed to update the macro to override this case by using unbounded preceding. I also took the opportunity to update the exposures of the new report. # 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. - [X] I have checked for DRY opportunities with other models and docs. - [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: #26085
29 lines
855 B
SQL
29 lines
855 B
SQL
/*
|
|
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.
|
|
|
|
If include_all_history is True, then X is ignored.
|
|
*/
|
|
{% macro calculate_aggregation_between_preceeding_x_and_y(
|
|
metric,
|
|
aggregation="sum",
|
|
partition_by="id_deal",
|
|
order_by="date",
|
|
x=12,
|
|
y=1,
|
|
include_all_history=False
|
|
) %}
|
|
{{ aggregation }} ({{ metric }}) over (
|
|
partition by {{ partition_by }}
|
|
order by
|
|
{{ order_by }} rows between
|
|
{% if include_all_history %}
|
|
unbounded preceding
|
|
{% else %}
|
|
{{ x }} preceding
|
|
{% endif %}
|
|
and {{ y }} preceding
|
|
) as {{ aggregation }}_{{ metric }}
|
|
{% endmacro %}
|