Merged PR 3924: First version of time window aggregated metrics by deal

# Description

This model aggregates at monthly by deal level different metrics for AM reporting purposes. It also includes revenue retained ratios for client profitability assessment.

There's part of the existing AM report that could be simplified, likely, by using the new macro. This will be explored in a separated PR, if it applies.

# 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. ** Checked and there might be possibilities to simplify the code. I'll check ones I finish this line of work**
- [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: #25829
This commit is contained in:
Oriol Roqué Paniagua 2025-01-03 08:07:16 +00:00
parent 0d7b5ac88a
commit a61da137fa
4 changed files with 590 additions and 4 deletions

View file

@ -0,0 +1,19 @@
/*
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.
*/
{% macro calculate_aggregation_between_preceeding_x_and_y(
metric,
aggregation="sum",
partition_by="id_deal",
order_by="date",
x=12,
y=1
) %}
{{ aggregation }} ({{ metric }}) over (
partition by {{ partition_by }}
order by {{ order_by }} rows between {{ x }} preceding and {{ y }} preceding
) as {{ aggregation }}_{{ metric }}
{% endmacro %}