data-dwh-dbt-project/models/intermediate/kpis/int_kpis__dimension_deals.sql

86 lines
3.3 KiB
MySQL
Raw Normal View History

Merged PR 3914: Include Hubspot deals for KPIs # Description Context: I'm intending to work on Account Managers reporting, that mostly will include reporting at Deal level the Resolutions Payouts as well as the new Retained metrics. While checking the great increase on Resolutions Payouts for October 2024: ![image (2).png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image%20%282%29.png) I decided to take a quick look into the main players... and surprise surprise we have Guesty: ![image.png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image.png) So Guesty represents 37k over the 73K of October. 50%. Not bad. The main issue is that we've been aware for months now (since Churn efforts, mostly) that we're not reporting in KPIs those deals that are NOT created in Core. Most notably, API deals which includes... well, Guesty. So creating this kind of in-depth Account Managers improvement without reporting Guesty I think it would be very misleading. Note that the overall figures (Global dimension) are still accurate, though. What's new: * A new model named `int_kpis__dimension_deals` that basically retrieves Deals from both Core (as before) and Hubspot. It combines information from both and mostly assumes Hubspot as a better source of information than Core - although we do not have the Main Billing Country there afaik. * Propagates changes, mostly in the monthly by deal view of Main KPIs. Here I confirm that now Guesty appears, and it only has metrics that come from Xero (APIs Revenue, Total Revenue, Resolutions, etc) # 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: #25829
2024-12-31 15:12:38 +00:00
{{ config(materialized="table", unique_key="id_deal") }}
with
hubspot_deals as (
2025-01-14 16:46:07 +01:00
select
id_deal,
deal_name as main_deal_name,
live_date_utc as deal_start_date,
date_trunc('month', live_date_utc) as deal_start_month,
cancellation_date_utc as deal_cancellation_date,
date_trunc('month', cancellation_date_utc) as deal_cancellation_month,
case
when amount_of_properties between 1 and 5
then '01-05'
when amount_of_properties between 6 and 20
then '06-20'
when amount_of_properties between 21 and 60
then '21-60'
when amount_of_properties >= 61
then '61+'
else 'UNSET'
end as hubspot_listing_segmentation
Merged PR 3914: Include Hubspot deals for KPIs # Description Context: I'm intending to work on Account Managers reporting, that mostly will include reporting at Deal level the Resolutions Payouts as well as the new Retained metrics. While checking the great increase on Resolutions Payouts for October 2024: ![image (2).png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image%20%282%29.png) I decided to take a quick look into the main players... and surprise surprise we have Guesty: ![image.png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image.png) So Guesty represents 37k over the 73K of October. 50%. Not bad. The main issue is that we've been aware for months now (since Churn efforts, mostly) that we're not reporting in KPIs those deals that are NOT created in Core. Most notably, API deals which includes... well, Guesty. So creating this kind of in-depth Account Managers improvement without reporting Guesty I think it would be very misleading. Note that the overall figures (Global dimension) are still accurate, though. What's new: * A new model named `int_kpis__dimension_deals` that basically retrieves Deals from both Core (as before) and Hubspot. It combines information from both and mostly assumes Hubspot as a better source of information than Core - although we do not have the Main Billing Country there afaik. * Propagates changes, mostly in the monthly by deal view of Main KPIs. Here I confirm that now Guesty appears, and it only has metrics that come from Xero (APIs Revenue, Total Revenue, Resolutions, etc) # 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: #25829
2024-12-31 15:12:38 +00:00
from {{ ref("int_hubspot__deal") }}
where live_date_utc is not null
),
core_deals as (
select
id_deal,
main_deal_name,
first_created_date_utc as deal_start_date,
2025-01-14 16:46:07 +01:00
date_trunc('month', first_created_date_utc) as deal_start_month,
Merged PR 3914: Include Hubspot deals for KPIs # Description Context: I'm intending to work on Account Managers reporting, that mostly will include reporting at Deal level the Resolutions Payouts as well as the new Retained metrics. While checking the great increase on Resolutions Payouts for October 2024: ![image (2).png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image%20%282%29.png) I decided to take a quick look into the main players... and surprise surprise we have Guesty: ![image.png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image.png) So Guesty represents 37k over the 73K of October. 50%. Not bad. The main issue is that we've been aware for months now (since Churn efforts, mostly) that we're not reporting in KPIs those deals that are NOT created in Core. Most notably, API deals which includes... well, Guesty. So creating this kind of in-depth Account Managers improvement without reporting Guesty I think it would be very misleading. Note that the overall figures (Global dimension) are still accurate, though. What's new: * A new model named `int_kpis__dimension_deals` that basically retrieves Deals from both Core (as before) and Hubspot. It combines information from both and mostly assumes Hubspot as a better source of information than Core - although we do not have the Main Billing Country there afaik. * Propagates changes, mostly in the monthly by deal view of Main KPIs. Here I confirm that now Guesty appears, and it only has metrics that come from Xero (APIs Revenue, Total Revenue, Resolutions, etc) # 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: #25829
2024-12-31 15:12:38 +00:00
main_billing_country_iso_3_per_deal
from {{ ref("int_core__deal") }}
),
integrations_per_user as (
select
icuh.id_deal,
sci.id_superhog_user as id_user,
scit.display_name as active_pms
from {{ ref("stg_core__integration") }} sci
left join
{{ ref("stg_core__integration_type") }} scit
on sci.id_integration_type = scit.id_integration_type
left join
{{ ref("int_core__user_host") }} icuh
on sci.id_superhog_user = icuh.id_user_host
where sci.is_active = true and icuh.is_missing_id_deal = false
),
integrations_per_deal as (
select id_deal, string_agg(distinct active_pms, ', ') as distinct_active_pms
from integrations_per_user
group by id_deal
),
combined_deals as (
select
coalesce(hd.id_deal, cd.id_deal) as id_deal,
coalesce(hd.main_deal_name, cd.main_deal_name) as main_deal_name,
cd.main_billing_country_iso_3_per_deal,
min(
coalesce(hd.deal_start_date, cd.deal_start_date)
2025-01-14 16:46:07 +01:00
) as effective_deal_start_date_utc,
min(
coalesce(hd.deal_start_month, cd.deal_start_month)
) as effective_deal_start_month,
min(hd.deal_cancellation_date) as effective_deal_cancellation_date_utc,
min(hd.deal_cancellation_month) as effective_deal_cancellation_month,
min(hd.hubspot_listing_segmentation) as hubspot_listing_segmentation
from hubspot_deals hd
full outer join core_deals cd on hd.id_deal = cd.id_deal
group by 1, 2, 3
Merged PR 3914: Include Hubspot deals for KPIs # Description Context: I'm intending to work on Account Managers reporting, that mostly will include reporting at Deal level the Resolutions Payouts as well as the new Retained metrics. While checking the great increase on Resolutions Payouts for October 2024: ![image (2).png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image%20%282%29.png) I decided to take a quick look into the main players... and surprise surprise we have Guesty: ![image.png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image.png) So Guesty represents 37k over the 73K of October. 50%. Not bad. The main issue is that we've been aware for months now (since Churn efforts, mostly) that we're not reporting in KPIs those deals that are NOT created in Core. Most notably, API deals which includes... well, Guesty. So creating this kind of in-depth Account Managers improvement without reporting Guesty I think it would be very misleading. Note that the overall figures (Global dimension) are still accurate, though. What's new: * A new model named `int_kpis__dimension_deals` that basically retrieves Deals from both Core (as before) and Hubspot. It combines information from both and mostly assumes Hubspot as a better source of information than Core - although we do not have the Main Billing Country there afaik. * Propagates changes, mostly in the monthly by deal view of Main KPIs. Here I confirm that now Guesty appears, and it only has metrics that come from Xero (APIs Revenue, Total Revenue, Resolutions, etc) # 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: #25829
2024-12-31 15:12:38 +00:00
)
select
cd.id_deal,
cd.main_deal_name,
2025-01-09 16:31:22 +01:00
case
when ipd.distinct_active_pms is null then false else true
end as has_active_pms,
ipd.distinct_active_pms as active_pms_list,
Merged PR 3914: Include Hubspot deals for KPIs # Description Context: I'm intending to work on Account Managers reporting, that mostly will include reporting at Deal level the Resolutions Payouts as well as the new Retained metrics. While checking the great increase on Resolutions Payouts for October 2024: ![image (2).png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image%20%282%29.png) I decided to take a quick look into the main players... and surprise surprise we have Guesty: ![image.png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/3914/attachments/image.png) So Guesty represents 37k over the 73K of October. 50%. Not bad. The main issue is that we've been aware for months now (since Churn efforts, mostly) that we're not reporting in KPIs those deals that are NOT created in Core. Most notably, API deals which includes... well, Guesty. So creating this kind of in-depth Account Managers improvement without reporting Guesty I think it would be very misleading. Note that the overall figures (Global dimension) are still accurate, though. What's new: * A new model named `int_kpis__dimension_deals` that basically retrieves Deals from both Core (as before) and Hubspot. It combines information from both and mostly assumes Hubspot as a better source of information than Core - although we do not have the Main Billing Country there afaik. * Propagates changes, mostly in the monthly by deal view of Main KPIs. Here I confirm that now Guesty appears, and it only has metrics that come from Xero (APIs Revenue, Total Revenue, Resolutions, etc) # 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: #25829
2024-12-31 15:12:38 +00:00
cd.main_billing_country_iso_3_per_deal,
2025-01-14 16:46:07 +01:00
cd.effective_deal_start_date_utc,
cd.effective_deal_start_month,
cd.effective_deal_cancellation_date_utc,
cd.effective_deal_cancellation_month,
cd.hubspot_listing_segmentation
from combined_deals cd
left join integrations_per_deal ipd on cd.id_deal = ipd.id_deal