data-dwh-dbt-project/models/intermediate/kpis/int_kpis__agg_daily_deals.sql
Oriol Roqué Paniagua 8c23f91242 Merged PR 3451: Adds Deal Daily Lifecycle and metrics
# Description

Changes:
* Creates lifecycle_daily_deal, metric_daily_deals and agg_daily_deals. These follow a different strategy due to the nature of the metrics
* Modifies the dimension macro to ensure deal dimension is included in all models except these ones
* Fixes production issue on currently deployed deal lifecycle and metrics

# 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: #23566
2024-11-07 10:49:06 +00:00

33 lines
1.2 KiB
SQL

{% set dimensions = get_kpi_dimensions_per_model("DEALS") %}
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
{% for dimension in dimensions %}
select
-- Unique Key --
d.date,
{{ dimension.dimension }} as dimension,
{{ dimension.dimension_value }} as dimension_value,
-- Date Attributes --
d.is_current_month,
d.is_end_of_month,
d.is_month_to_date,
-- Metrics --
sum(new_deals) as new_deals,
sum(never_booked_deals) as never_booked_deals,
sum(first_time_booked_deals) as first_time_booked_deals,
sum(active_deals) as active_deals,
sum(churning_deals) as churning_deals,
sum(inactive_deals) as inactive_deals,
sum(reactivated_deals) as reactivated_deals,
sum(deals_booked_in_month) as deals_booked_in_month,
sum(deals_booked_in_6_months) as deals_booked_in_6_months,
sum(deals_booked_in_12_months) as deals_booked_in_12_months
from {{ ref("int_kpis__dimension_dates") }} d
left join {{ ref("int_kpis__metric_daily_deals") }} as mdd on d.date = mdd.date
group by 1, 2, 3, 4, 5, 6
{% if not loop.last %}
union all
{% endif %}
{% endfor %}