Adding PMS info for Account Margin report
This commit is contained in:
parent
04a10cf9c5
commit
bd25b473fb
7 changed files with 225 additions and 79 deletions
|
|
@ -12,14 +12,44 @@ with
|
|||
first_created_date_utc as deal_start_date,
|
||||
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)
|
||||
) as effective_deal_start_date_utc
|
||||
from hubspot_deals hd
|
||||
full outer join core_deals cd on hd.id_deal = cd.id_deal
|
||||
group by 1, 2, 3
|
||||
)
|
||||
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.id_deal,
|
||||
cd.main_deal_name,
|
||||
case when ipd.distinct_active_pms is null then false else true end as active_pms,
|
||||
ipd.distinct_active_pms as pms,
|
||||
cd.main_billing_country_iso_3_per_deal,
|
||||
min(
|
||||
coalesce(hd.deal_start_date, cd.deal_start_date)
|
||||
) as effective_deal_start_date_utc
|
||||
from hubspot_deals hd
|
||||
full outer join core_deals cd on hd.id_deal = cd.id_deal
|
||||
group by 1, 2, 3
|
||||
cd.effective_deal_start_date_utc
|
||||
from combined_deals cd
|
||||
left join integrations_per_deal ipd on cd.id_deal = ipd.id_deal
|
||||
|
|
|
|||
|
|
@ -450,6 +450,17 @@ models:
|
|||
in both systems, Hubspot data will take precedence in terms of deal name.
|
||||
tests:
|
||||
- not_null
|
||||
- name: active_pms
|
||||
data_type: boolean
|
||||
description: |
|
||||
Does the deal have an active associated PMS.
|
||||
tests:
|
||||
- not_null
|
||||
- name: pms
|
||||
data_type: string
|
||||
description: |
|
||||
Name of the active PMS associated with the deal. It can have more than
|
||||
one PMS associated with it. It can be null doesn't have any PMS associated.
|
||||
- name: main_billing_country_iso_3_per_deal
|
||||
data_type: string
|
||||
description: |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue