Merged PR 5162: Fixes month shift on revenue share and rank

# Description

Fixes the Account Growth issue on the rank/share on revenue metrics.

Issue was that the share needs to be shifted one month for account computation; meaning that the impact score of April relies on the share from March (as there's no April revenue data).

The shift also affected the rank as it's based on the share.

Solution is:
* Re-bring actual revenue share and attribute it to the correct month
* Apply a coalesce giving priority to the revenue share/rank from the correct month. If no data is available (ongoing month), show share/rank of previous month. This is intended to help quantify account importance in the ongoing month - as it's actually the case in the report

Tested locally + run in prod to check the report performance. Small note, this makes revenue share not adding up anymore to 100% as accounts that go live in the same month are excluded. This is exactly the same as for Billable Items.

# 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.
- [ ] 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: #30013
This commit is contained in:
Oriol Roqué Paniagua 2025-05-08 06:15:44 +00:00
parent 4475c8d56f
commit a3038089e8

View file

@ -198,20 +198,38 @@ select
-- Total Revenue Metrics
rpd.current_month_total_revenue_in_gbp,
rpd.rolling_12_months_total_revenue_in_gbp,
gai.share_total_revenue_rolling_12_months,
-- If exists, use the real revenue contribution to the month
-- Else, use the global revenue contribution from the previous month
coalesce(
drc.share_total_revenue_rolling_12_months,
gai.share_total_revenue_rolling_12_months
) as share_total_revenue_rolling_12_months,
row_number() over (
partition by gai.end_date
order by gai.share_total_revenue_rolling_12_months desc, gai.id_deal
order by
coalesce(
drc.share_total_revenue_rolling_12_months,
gai.share_total_revenue_rolling_12_months
) desc,
gai.id_deal
) as rank_total_revenue_rolling_12_months,
-- Revenue Retained Post Resolutions Metrics
rpd.current_month_revenue_retained_post_resolutions_in_gbp,
rpd.rolling_12_months_revenue_retained_post_resolutions_in_gbp,
gai.share_revenue_retained_post_resolutions_rolling_12_months,
-- If exists, use the real revenue contribution to the month
-- Else, use the global revenue contribution from the previous month
coalesce(
drc.share_revenue_retained_post_resolutions_rolling_12_months,
gai.share_revenue_retained_post_resolutions_rolling_12_months
) as share_revenue_retained_post_resolutions_rolling_12_months,
row_number() over (
partition by gai.end_date
order by
gai.share_revenue_retained_post_resolutions_rolling_12_months desc,
coalesce(
drc.share_revenue_retained_post_resolutions_rolling_12_months,
gai.share_revenue_retained_post_resolutions_rolling_12_months
) desc,
gai.id_deal
) as rank_revenue_retained_post_resolutions_rolling_12_months,
@ -233,6 +251,11 @@ left join
-- Keep Revenue attributed to the real month (will be null in the ongoing month)
on gai.id_deal = rpd.id_deal
and gai.end_date = rpd.date
left join
deal_revenue_contribution_per_month drc
-- Keep Revenue Contribution to the real month (will be null in the ongoing month)
on gai.id_deal = drc.id_deal
and gai.end_date = drc.date
left join int_kpis__dimension_deals ikdd on gai.id_deal = ikdd.id_deal
left join int_hubspot__deal d on gai.id_deal = d.id_deal
left join