diff --git a/models/intermediate/cross/int_monthly_account_revenue_impact_from_growth.sql b/models/intermediate/cross/int_monthly_account_revenue_impact_from_growth.sql index 79258bf..964dfa2 100644 --- a/models/intermediate/cross/int_monthly_account_revenue_impact_from_growth.sql +++ b/models/intermediate/cross/int_monthly_account_revenue_impact_from_growth.sql @@ -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