Merged PR 5058: Propagate API deals to growth score
# Description I opted to name the combination of (Platform) Billable Bookings and (API) Billable Verifications as Billable Items. This is to ensure consistent naming. Changes: * Renamed `int_kpis_projected__agg_daily_billable_bookings` to `int_kpis_projected__agg_daily_billable_items`. This now has a new CTE named combination_of_billable_items that combines both API and Platform billable items. Renamed any "bookings" field to "items". * Renamed `int_kpis_projected__agg_monthly_billable_bookings` to `int_kpis_projected__agg_monthly_billable_items`. Renamed any "bookings" field to "items". * Renamed `int_billable_bookings_growth_score_by_deal` to `int_billable_items_growth_score_by_deal`. This now has a new CTE named `aggregated_monthly_billable_items` that combines the historical information both API and Platform on billable items. Renamed any "bookings" field to "items". * Changes Schema accordingly. Small note here that the assert dimension completeness stops working since there's dimensions specific to API or Platform, thus I removed 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. - [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: #29374
This commit is contained in:
parent
8901cc85ec
commit
0ffcfca6a8
6 changed files with 288 additions and 258 deletions
|
|
@ -1,115 +0,0 @@
|
|||
{{ config(materialized="table", unique_key=["end_date", "id_deal"]) }}
|
||||
with
|
||||
int_kpis_projected__agg_monthly_billable_bookings as (
|
||||
select *
|
||||
from {{ ref("int_kpis_projected__agg_monthly_billable_bookings") }}
|
||||
where dimension = 'by_deal' and dimension_value <> 'UNSET'
|
||||
),
|
||||
int_kpis__agg_monthly_billable_bookings as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_billable_bookings") }}
|
||||
where dimension = 'by_deal' and dimension_value <> 'UNSET'
|
||||
),
|
||||
billable_bookings_per_month_with_projection as (
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
dimension_value as id_deal,
|
||||
current_month_projected_billable_bookings
|
||||
as current_month_billable_bookings,
|
||||
current_month_projected_billable_bookings
|
||||
/ sum(current_month_projected_billable_bookings) over (
|
||||
partition by end_date order by end_date
|
||||
) as current_month_share_billable_bookings,
|
||||
historical_monthly_mean_absolute_error as projection_mean_absolute_error,
|
||||
historical_monthly_mean_absolute_percentage_error
|
||||
as projection_mean_absolute_percentage_error,
|
||||
true as are_billable_bookings_projected
|
||||
from int_kpis_projected__agg_monthly_billable_bookings
|
||||
union all
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
dimension_value as id_deal,
|
||||
billable_bookings as current_month_billable_bookings,
|
||||
billable_bookings / sum(billable_bookings) over (
|
||||
partition by end_date order by end_date
|
||||
) as current_month_share_billable_bookings,
|
||||
null as projection_mean_absolute_error,
|
||||
null as projection_mean_absolute_percentage_error,
|
||||
false as are_billable_bookings_projected
|
||||
from int_kpis__agg_monthly_billable_bookings
|
||||
),
|
||||
billable_bookings_growth_score as (
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
id_deal,
|
||||
-- Billable Bookings (Absolute) --
|
||||
current_month_billable_bookings,
|
||||
avg(current_month_billable_bookings) over (
|
||||
partition by id_deal
|
||||
order by end_date asc
|
||||
rows between 3 preceding and 1 preceding
|
||||
) as prior_3_months_avg_monthly_billable_bookings,
|
||||
current_month_billable_bookings
|
||||
/ avg(current_month_billable_bookings) over (
|
||||
partition by id_deal
|
||||
order by end_date asc
|
||||
rows between 3 preceding and 1 preceding
|
||||
)
|
||||
- 1 as growth_vs_prior_3_avg_billable_bookings,
|
||||
|
||||
-- Share of Billable Bookings per Deal over Total --
|
||||
current_month_share_billable_bookings,
|
||||
avg(current_month_share_billable_bookings) over (
|
||||
partition by id_deal
|
||||
order by end_date asc
|
||||
rows between 3 preceding and 1 preceding
|
||||
) as prior_3_months_avg_monthly_share_billable_bookings,
|
||||
current_month_share_billable_bookings
|
||||
/ avg(current_month_share_billable_bookings) over (
|
||||
partition by id_deal
|
||||
order by end_date asc
|
||||
rows between 3 preceding and 1 preceding
|
||||
)
|
||||
- 1 as growth_vs_prior_3_avg_share_billable_bookings,
|
||||
-- Projection Reference --
|
||||
projection_mean_absolute_error,
|
||||
projection_mean_absolute_percentage_error,
|
||||
are_billable_bookings_projected
|
||||
from billable_bookings_per_month_with_projection
|
||||
)
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
id_deal,
|
||||
-- Billable Bookings (Absolute) --
|
||||
current_month_billable_bookings,
|
||||
prior_3_months_avg_monthly_billable_bookings,
|
||||
-- Share of Billable Bookings per Deal over Total --
|
||||
current_month_share_billable_bookings,
|
||||
prior_3_months_avg_monthly_share_billable_bookings,
|
||||
-- Specific Growth Scores --
|
||||
growth_vs_prior_3_avg_billable_bookings,
|
||||
growth_vs_prior_3_avg_share_billable_bookings,
|
||||
-- Combined Growth Score --
|
||||
least(
|
||||
greatest(
|
||||
coalesce(
|
||||
(
|
||||
growth_vs_prior_3_avg_billable_bookings
|
||||
+ growth_vs_prior_3_avg_share_billable_bookings
|
||||
)
|
||||
/ 2,
|
||||
0
|
||||
),
|
||||
-1
|
||||
),
|
||||
1
|
||||
) as growth_score,
|
||||
-- Projection Reference --
|
||||
projection_mean_absolute_error,
|
||||
projection_mean_absolute_percentage_error,
|
||||
are_billable_bookings_projected
|
||||
from billable_bookings_growth_score
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
{{ config(materialized="table", unique_key=["end_date", "id_deal"]) }}
|
||||
with
|
||||
int_kpis_projected__agg_monthly_billable_items as (
|
||||
select *
|
||||
from {{ ref("int_kpis_projected__agg_monthly_billable_items") }}
|
||||
where dimension = 'by_deal' and dimension_value <> 'UNSET'
|
||||
),
|
||||
int_kpis__agg_monthly_billable_bookings as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_billable_bookings") }}
|
||||
where dimension = 'by_deal' and dimension_value <> 'UNSET'
|
||||
),
|
||||
int_kpis__agg_monthly_api_billable_verifications as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_api_billable_verifications") }}
|
||||
where dimension = 'by_deal' and dimension_value <> 'UNSET'
|
||||
),
|
||||
aggregated_monthly_billable_items as (
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
dimension_value as id_deal,
|
||||
billable_bookings as current_month_billable_items
|
||||
from int_kpis__agg_monthly_billable_bookings
|
||||
union all
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
dimension_value as id_deal,
|
||||
billable_verifications as current_month_billable_items
|
||||
from int_kpis__agg_monthly_api_billable_verifications
|
||||
),
|
||||
billable_items_per_month_with_projection as (
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
dimension_value as id_deal,
|
||||
current_month_projected_billable_items as current_month_billable_items,
|
||||
current_month_projected_billable_items
|
||||
/ sum(current_month_projected_billable_items) over (
|
||||
partition by end_date order by end_date
|
||||
) as current_month_share_billable_items,
|
||||
historical_monthly_mean_absolute_error as projection_mean_absolute_error,
|
||||
historical_monthly_mean_absolute_percentage_error
|
||||
as projection_mean_absolute_percentage_error,
|
||||
true as are_billable_items_projected
|
||||
from int_kpis_projected__agg_monthly_billable_items
|
||||
union all
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
id_deal,
|
||||
current_month_billable_items,
|
||||
current_month_billable_items / sum(current_month_billable_items) over (
|
||||
partition by end_date order by end_date
|
||||
) as current_month_share_billable_items,
|
||||
null as projection_mean_absolute_error,
|
||||
null as projection_mean_absolute_percentage_error,
|
||||
false as are_billable_items_projected
|
||||
from aggregated_monthly_billable_items
|
||||
),
|
||||
billable_items_growth_score as (
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
id_deal,
|
||||
-- Billable Bookings (Absolute) --
|
||||
current_month_billable_items,
|
||||
avg(current_month_billable_items) over (
|
||||
partition by id_deal
|
||||
order by end_date asc
|
||||
rows between 3 preceding and 1 preceding
|
||||
) as prior_3_months_avg_monthly_billable_items,
|
||||
current_month_billable_items / avg(current_month_billable_items) over (
|
||||
partition by id_deal
|
||||
order by end_date asc
|
||||
rows between 3 preceding and 1 preceding
|
||||
)
|
||||
- 1 as growth_vs_prior_3_avg_billable_items,
|
||||
|
||||
-- Share of Billable Bookings per Deal over Total --
|
||||
current_month_share_billable_items,
|
||||
avg(current_month_share_billable_items) over (
|
||||
partition by id_deal
|
||||
order by end_date asc
|
||||
rows between 3 preceding and 1 preceding
|
||||
) as prior_3_months_avg_monthly_share_billable_items,
|
||||
current_month_share_billable_items
|
||||
/ avg(current_month_share_billable_items) over (
|
||||
partition by id_deal
|
||||
order by end_date asc
|
||||
rows between 3 preceding and 1 preceding
|
||||
)
|
||||
- 1 as growth_vs_prior_3_avg_share_billable_items,
|
||||
-- Projection Reference --
|
||||
projection_mean_absolute_error,
|
||||
projection_mean_absolute_percentage_error,
|
||||
are_billable_items_projected
|
||||
from billable_items_per_month_with_projection
|
||||
)
|
||||
select
|
||||
start_date,
|
||||
end_date,
|
||||
id_deal,
|
||||
-- Billable Bookings (Absolute) --
|
||||
current_month_billable_items,
|
||||
prior_3_months_avg_monthly_billable_items,
|
||||
-- Share of Billable Bookings per Deal over Total --
|
||||
current_month_share_billable_items,
|
||||
prior_3_months_avg_monthly_share_billable_items,
|
||||
-- Specific Growth Scores --
|
||||
growth_vs_prior_3_avg_billable_items,
|
||||
growth_vs_prior_3_avg_share_billable_items,
|
||||
-- Combined Growth Score --
|
||||
least(
|
||||
greatest(
|
||||
coalesce(
|
||||
(
|
||||
growth_vs_prior_3_avg_billable_items
|
||||
+ growth_vs_prior_3_avg_share_billable_items
|
||||
)
|
||||
/ 2,
|
||||
0
|
||||
),
|
||||
-1
|
||||
),
|
||||
1
|
||||
) as growth_score,
|
||||
-- Projection Reference --
|
||||
projection_mean_absolute_error,
|
||||
projection_mean_absolute_percentage_error,
|
||||
are_billable_items_projected
|
||||
from billable_items_growth_score
|
||||
|
|
@ -3225,18 +3225,18 @@ models:
|
|||
When precision and recall are far apart, the F2 score will be closer to the
|
||||
lower of the two.
|
||||
|
||||
- name: int_billable_bookings_growth_score_by_deal
|
||||
- name: int_billable_items_growth_score_by_deal
|
||||
description: |
|
||||
This model computes the growth score of the billable bookings for each deal.
|
||||
This model computes the growth score of the billable items for each deal.
|
||||
The growth score is computed as the average between:
|
||||
- The billable bookings of a given month vs. the average of the previous
|
||||
- The billable items of a given month vs. the average of the previous
|
||||
3 months.
|
||||
- The share a deal has in terms of billable bookings of a given month
|
||||
- The share a deal has in terms of billable items of a given month
|
||||
if compared to the rest of the deals vs. the average of the previous 3
|
||||
months.
|
||||
The growth score is capped between -1 and 1.
|
||||
It is important to note that if we check the current month, the count of
|
||||
billable bookings and the corresponding share will be based on the projection,
|
||||
billable items and the corresponding share will be based on the projection,
|
||||
rather than the actual figure. In this case, the MAE and MAPE of the projected
|
||||
value are indicated in the model.
|
||||
While the growth score is computed at a monthly basis, the value will update
|
||||
|
|
@ -3274,12 +3274,12 @@ models:
|
|||
data_tests:
|
||||
- not_null
|
||||
|
||||
- name: current_month_billable_bookings
|
||||
- name: current_month_billable_items
|
||||
data_type: integer
|
||||
description: |
|
||||
Monthly billable bookings. If the month is in progress
|
||||
Monthly billable items. If the month is in progress
|
||||
then this value corresponds to the projected figure.
|
||||
This is indicated by "are_billable_bookings_projected"
|
||||
This is indicated by "are_billable_items_projected"
|
||||
flag.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
|
@ -3287,10 +3287,10 @@ models:
|
|||
min_value: 0
|
||||
strictly: false
|
||||
|
||||
- name: prior_3_months_avg_monthly_billable_bookings
|
||||
- name: prior_3_months_avg_monthly_billable_items
|
||||
data_type: integer
|
||||
description: |
|
||||
Average of the billable bookings for the previous 3 months.
|
||||
Average of the billable items for the previous 3 months.
|
||||
If the selected range is from 1st April 2025 to 30th April 2025,
|
||||
then this average will be based between 1st January 2025 to
|
||||
31st March 2025.
|
||||
|
|
@ -3299,12 +3299,12 @@ models:
|
|||
min_value: 0
|
||||
strictly: false
|
||||
|
||||
- name: current_month_share_billable_bookings
|
||||
- name: current_month_share_billable_items
|
||||
data_type: decimal
|
||||
description: |
|
||||
Share of the billable bookings for a given deal in the current month.
|
||||
Share of the billable items for a given deal in the current month.
|
||||
If the month is in progress then this value corresponds to the
|
||||
projected figure. This is indicated by "are_billable_bookings_projected"
|
||||
projected figure. This is indicated by "are_billable_items_projected"
|
||||
flag.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
|
@ -3312,10 +3312,10 @@ models:
|
|||
min_value: 0
|
||||
strictly: false
|
||||
|
||||
- name: prior_3_months_avg_monthly_share_billable_bookings
|
||||
- name: prior_3_months_avg_monthly_share_billable_items
|
||||
data_type: decimal
|
||||
description: |
|
||||
Average of the share of the billable bookings for a given deal in the
|
||||
Average of the share of the billable items for a given deal in the
|
||||
previous 3 months. If the selected range is from 1st April 2025 to
|
||||
30th April 2025, then this average will be based between 1st January
|
||||
2025 to 31st March 2025.
|
||||
|
|
@ -3324,21 +3324,21 @@ models:
|
|||
min_value: 0
|
||||
strictly: false
|
||||
|
||||
- name: growth_vs_prior_3_avg_billable_bookings
|
||||
- name: growth_vs_prior_3_avg_billable_items
|
||||
data_type: decimal
|
||||
description: |
|
||||
Growth score of the billable bookings based purely on the relative
|
||||
difference between the current month billable bookings vs. the
|
||||
Growth score of the billable items based purely on the relative
|
||||
difference between the current month billable items vs. the
|
||||
prior 3 months average.
|
||||
This is a subcomputation of the growth score, for information
|
||||
purposes.
|
||||
It can be null.
|
||||
|
||||
- name: growth_vs_prior_3_avg_share_billable_bookings
|
||||
- name: growth_vs_prior_3_avg_share_billable_items
|
||||
data_type: decimal
|
||||
description: |
|
||||
Growth score of the billable bookings based purely on the relative
|
||||
difference between the current month share billable bookings vs. the
|
||||
Growth score of the billable items based purely on the relative
|
||||
difference between the current month share billable items vs. the
|
||||
prior 3 months average.
|
||||
This is a subcomputation of the growth score, for information
|
||||
purposes.
|
||||
|
|
@ -3347,10 +3347,10 @@ models:
|
|||
- name: growth_score
|
||||
data_type: decimal
|
||||
description: |
|
||||
Growth score of the billable bookings, based on the average between:
|
||||
- The billable bookings of a given month vs. the average of the previous
|
||||
Growth score of the billable items, based on the average between:
|
||||
- The billable items of a given month vs. the average of the previous
|
||||
3 months.
|
||||
- The share a deal has in terms of billable bookings of a given month
|
||||
- The share a deal has in terms of billable items of a given month
|
||||
if compared to the rest of the deals vs. the average of the previous 3
|
||||
months.
|
||||
The growth score is capped between -1 and 1.
|
||||
|
|
@ -3365,7 +3365,7 @@ models:
|
|||
- name: projection_mean_absolute_error
|
||||
data_type: decimal
|
||||
description: |
|
||||
Mean absolute error of the projection of the billable bookings.
|
||||
Mean absolute error of the projection of the billable items.
|
||||
It is null if the month is not in progress or value is projected
|
||||
but there's no prior data to compare the projection against.
|
||||
data_tests:
|
||||
|
|
@ -3376,7 +3376,7 @@ models:
|
|||
- name: projection_mean_absolute_percentage_error
|
||||
data_type: decimal
|
||||
description: |
|
||||
Mean absolute percentage error of the projection of the billable bookings.
|
||||
Mean absolute percentage error of the projection of the billable items.
|
||||
It is null if the month is not in progress or value is projected
|
||||
but there's no prior data to compare the projection against.
|
||||
data_tests:
|
||||
|
|
@ -3384,12 +3384,12 @@ models:
|
|||
min_value: 0
|
||||
strictly: false
|
||||
|
||||
- name: are_billable_bookings_projected
|
||||
- name: are_billable_items_projected
|
||||
data_type: boolean
|
||||
description: |
|
||||
Flag indicating if the billable bookings are projected or not.
|
||||
Flag indicating if the billable items are projected or not.
|
||||
If the month is in progress then this value corresponds to the
|
||||
projected figure. This is indicated by "are_billable_bookings_projected"
|
||||
projected figure. This is indicated by "are_billable_items_projected"
|
||||
flag.
|
||||
data_tests:
|
||||
- not_null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue