Merged PR 3183: Bugfixes on top losers

# Description

- Bugfix on nullif then 0 - it was applied to the numerator of Revenue computation, which made MoM growth be considered as null and propagated as 0 in the scores, which is not true.
- Bugfix on cast as numeric - this was introduced because PBI didn't read well some decimal figures when loading the data. However this impacted somehow in the score by some weird magic I don't understand. I just replace the casts by rounds, that are applied after the computation of the scores, and PBI seems happy with it.

# 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.
- [NA] I have checked for DRY opportunities with other models and docs.
- [NA] 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: #22635
This commit is contained in:
Oriol Roqué Paniagua 2024-10-15 15:51:04 +00:00
parent da8c2e9fab
commit 35b6472b48

View file

@ -102,16 +102,16 @@ with
-- In these YoY and MoM computations, if negative revenue is found,
-- no value is reported. This is because otherwise relative increments
-- are wrong.
nullif(greatest(given_month.revenue_in_gbp, 0), 0)
greatest(given_month.revenue_in_gbp, 0)
/ nullif(greatest(previous_1_month.revenue_in_gbp, 0), 0)
- 1 as mom_revenue_growth,
nullif(greatest(previous_1_month.revenue_in_gbp, 0), 0)
greatest(previous_1_month.revenue_in_gbp, 0)
/ nullif(greatest(previous_2_month.revenue_in_gbp, 0), 0)
- 1 as mom_1_month_shift_revenue_growth,
nullif(greatest(given_month.revenue_in_gbp, 0), 0)
greatest(given_month.revenue_in_gbp, 0)
/ nullif(greatest(previous_12_month.revenue_in_gbp, 0), 0)
- 1 as yoy_revenue_growth,
nullif(greatest(previous_1_month.revenue_in_gbp, 0), 0)
greatest(previous_1_month.revenue_in_gbp, 0)
/ nullif(greatest(previous_13_month.revenue_in_gbp, 0), 0)
- 1 as yoy_1_month_shift_revenue_growth,
@ -222,34 +222,22 @@ with
m.previous_2_month_revenue_in_gbp,
m.previous_12_month_revenue_in_gbp,
m.previous_13_month_revenue_in_gbp,
cast(m.mom_revenue_growth as numeric(19, 6)) as mom_revenue_growth,
cast(
m.mom_1_month_shift_revenue_growth as numeric(19, 6)
) as mom_1_month_shift_revenue_growth,
cast(m.yoy_revenue_growth as numeric(19, 6)) as yoy_revenue_growth,
cast(
m.yoy_1_month_shift_revenue_growth as numeric(19, 6)
) as yoy_1_month_shift_revenue_growth,
m.mom_revenue_growth,
m.mom_1_month_shift_revenue_growth,
m.yoy_revenue_growth,
m.yoy_1_month_shift_revenue_growth,
m.given_month_created_bookings,
m.previous_1_month_created_bookings,
m.previous_12_month_created_bookings,
cast(
m.mom_created_bookings_growth as numeric(19, 6)
) as mom_created_bookings_growth,
cast(
m.yoy_created_bookings_growth as numeric(19, 6)
) as yoy_created_bookings_growth,
m.mom_created_bookings_growth,
m.yoy_created_bookings_growth,
m.given_month_listings_booked_in_month,
m.previous_1_month_listings_booked_in_month,
m.previous_12_month_listings_booked_in_month,
cast(
m.mom_listings_booked_in_month_growth as numeric(19, 6)
) as mom_listings_booked_in_month_growth,
cast(
m.yoy_listings_booked_in_month_growth as numeric(19, 6)
) as yoy_listings_booked_in_month_growth,
m.mom_listings_booked_in_month_growth,
m.yoy_listings_booked_in_month_growth,
m.deal_created_bookings_12_months_window,
m.global_created_bookings_12_months_window,
@ -261,25 +249,28 @@ with
m.deal_contribution_share_to_global_revenue,
m.deal_contribution_rank_to_global_revenue,
100 * cast(
(
round(
100 * (
coalesce(m.mom_created_bookings_growth, 0)
+ coalesce(m.mom_listings_booked_in_month_growth, 0)
+ coalesce(m.mom_1_month_shift_revenue_growth, 0)
)
/ 3 as numeric(19, 6)
/ 3,
6
) as avg_mom_growth_score,
100 * cast(
(
round(
100 * (
coalesce(m.yoy_created_bookings_growth, 0)
+ coalesce(m.yoy_listings_booked_in_month_growth, 0)
+ coalesce(m.yoy_1_month_shift_revenue_growth, 0)
)
/ 3 as numeric(19, 6)
/ 3,
6
) as avg_yoy_growth_score,
100 * cast(
(
round(
100 * (
coalesce(m.yoy_created_bookings_growth, 0)
+ coalesce(m.yoy_listings_booked_in_month_growth, 0)
+ coalesce(m.yoy_1_month_shift_revenue_growth, 0)
@ -287,10 +278,11 @@ with
+ coalesce(m.mom_listings_booked_in_month_growth, 0)
+ coalesce(m.mom_1_month_shift_revenue_growth, 0)
)
/ 6 as numeric(19, 6)
/ 6,
6
) as avg_growth_score,
1000 * cast(
(
round(
1000 * (
(
coalesce(m.yoy_created_bookings_growth, 0)
+ coalesce(m.yoy_listings_booked_in_month_growth, 0)
@ -301,7 +293,8 @@ with
)
/ 6
)
* deal_contribution_share_to_global_revenue as numeric(19, 6)
* deal_contribution_share_to_global_revenue,
6
) as weighted_avg_growth_score
from metrics_attribution_to_given_month_per_deal m