269 lines
9.7 KiB
Plaintext
269 lines
9.7 KiB
Plaintext
expression UsingLimit = if limit_validity then " limit " & limit else ""
|
|
lineageTag: 93687462-63a3-4ca8-bb23-b980d178ec47
|
|
queryGroup: 参数
|
|
|
|
annotation PBI_NavigationStepName = 导航
|
|
|
|
annotation PBI_ResultType = Text
|
|
|
|
expression limit_validity = false meta [IsParameterQuery=true, Type="Logical", IsParameterQueryRequired=true]
|
|
lineageTag: f2b9ee23-c638-4eac-97c1-bb332e01a16f
|
|
queryGroup: 参数
|
|
|
|
annotation PBI_ResultType = Logical
|
|
|
|
annotation PBI_NavigationStepName = Navigation
|
|
|
|
expression limit = "10" meta [IsParameterQuery=true, Type="Text", IsParameterQueryRequired=true]
|
|
lineageTag: 13383dca-a800-45ed-b3a8-a2930ebf12c6
|
|
queryGroup: 参数
|
|
|
|
annotation PBI_ResultType = Text
|
|
|
|
/// 切换数据源Http路径使用
|
|
expression HttpPath = "sql/protocolv1/o/1064580724995799/1118-074021-486fqthp" meta [IsParameterQuery=true, List={"sql/protocolv1/o/1064580724995799/1118-074021-486fqthp", "sql/protocolv1/o/4124350841043461/0410-074134-do66802w"}, DefaultValue="sql/protocolv1/o/1064580724995799/1118-074021-486fqthp", Type="Text", IsParameterQueryRequired=true]
|
|
lineageTag: 9c59df5e-b5dc-4259-a64d-7ae346dcb3e7
|
|
queryGroup: 参数
|
|
|
|
annotation PBI_ResultType = Text
|
|
|
|
annotation PBI_NavigationStepName = Navigation
|
|
|
|
/// 切换数据目录使用
|
|
expression CatalogName = "catalog_e2_ngbi_qas" meta [IsParameterQuery=true, List={"catalog_e2_ngbi_qas", "catalog_e2_ngbi_prd"}, DefaultValue="catalog_e2_ngbi_prd", Type="Text", IsParameterQueryRequired=true]
|
|
lineageTag: f262d2bb-985d-406a-aacb-2c1d5b1430ac
|
|
queryGroup: 参数
|
|
|
|
annotation PBI_ResultType = Text
|
|
|
|
annotation PBI_NavigationStepName = Navigation
|
|
|
|
/// 切换服务器主机地址使用
|
|
expression ServerAddress = "adb-1064580724995799.3.databricks.azure.cn" meta [IsParameterQuery=true, List={"adb-1064580724995799.3.databricks.azure.cn", "adb-4124350841043461.1.databricks.azure.cn"}, DefaultValue="adb-1064580724995799.3.databricks.azure.cn", Type="Text", IsParameterQueryRequired=true]
|
|
lineageTag: 08b2d8cc-13df-48c6-970c-d788d6b1da4f
|
|
queryGroup: 参数
|
|
|
|
annotation PBI_ResultType = Text
|
|
|
|
annotation PBI_NavigationStepName = Navigation
|
|
|
|
expression Fact_Sales_SQL_limit =
|
|
let
|
|
Source = "--limit 10"
|
|
in
|
|
Source
|
|
lineageTag: 0f84d4f0-a309-44e1-a495-ffd9a5fdc993
|
|
queryGroup: Fact_Sales
|
|
|
|
annotation PBI_NavigationStepName = Navigation
|
|
|
|
annotation PBI_ResultType = Text
|
|
|
|
expression Config_MarketRatio = ```
|
|
let
|
|
Source =
|
|
Value.NativeQuery(
|
|
Databricks.Catalogs(
|
|
ServerAddress, HttpPath, [
|
|
Catalog = CatalogName,
|
|
Database = null,
|
|
EnableAutomaticProxyDiscovery = null,EnableQueryResultDownload="0"
|
|
]
|
|
){
|
|
[Name = CatalogName, Kind = "Database"]
|
|
}[Data],
|
|
"
|
|
with all_pack_pack_property as (
|
|
select Market,Pack_cod,CMPS_COD from dm.dm_aia_pack_property group by 1,2,3
|
|
union
|
|
select Market,iqvia_pack_code,CMPS_COD from dm.dm_zk_ec_pack_property group by 1,2,3
|
|
union
|
|
select Market,PACK_COD,CMPS_COD from dm.dm_chc_pack_property group by 1,2,3
|
|
union
|
|
select Market,PACK_COD,CMPS_COD from dm.dm_thc_pack_property group by 1,2,3
|
|
union
|
|
select Market,PACK_COD,CMPS_COD from dm.dm_ext_county_td_pack_property group by 1,2,3
|
|
union
|
|
select Market,iqvia_pack_code,CMPS_COD from dm.dm_zk_retail_dtp_pack_property group by 1,2,3
|
|
union
|
|
select Market,iqvia_pack_code,CMPS_COD from dm.dm_zk_retail_pack_property group by 1,2,3
|
|
union
|
|
select Market,pack_cod,CMPS_COD from DWS.dws_ims_td_market_ratio group by 1,2,3)
|
|
,brand_ratio as (
|
|
SELECT distinct market,
|
|
CASE WHEN length(cmps_cod) < 6 THEN RIGHT(CONCAT('000000',cmps_cod),6) ELSE cmps_cod END AS cmps_cod,
|
|
cmps_des,
|
|
CASE WHEN length(pack_cod) < 12 and pack_cod REGEXP '^[0-9]' THEN RIGHT(CONCAT('000000000000',pack_cod),12) ELSE pack_cod END AS pack_cod,
|
|
pack_des,
|
|
level,
|
|
type,
|
|
ratio
|
|
from dwd.dwd_gnd_ims_tblBrandRatio
|
|
)
|
|
,match_data as(
|
|
select
|
|
t1.PACK_COD,
|
|
t1.MARKET
|
|
-- case when t6.ratio is not null then t1.market_ratio * t6.ratio
|
|
-- else t1.market_ratio * NVL(t7.ratio,1)
|
|
-- end as VALUE_MARKET_RATIO,
|
|
-- case when t2.ratio is not null then t1.market_ratio * t2.ratio
|
|
-- else t1.market_ratio * NVL(t3.ratio,1)
|
|
-- end as UNIT_MARKET_RATIO,
|
|
-- t1.market_ratio as COUNTINGUNIT_MARKET_RATIO,
|
|
-- case when t4.ratio is not null then t1.market_ratio * t4.ratio
|
|
-- else t1.market_ratio * NVL(t5.ratio,1)
|
|
-- end as PDOT_MARKET_RATIO
|
|
|
|
,case
|
|
when t6.PACK_COD is not null then t6.level
|
|
when t7.CMPS_COD is not null then t7.level else null end as brandratio_value_level
|
|
,case
|
|
when t2.PACK_COD is not null then t2.level
|
|
when t3.CMPS_COD is not null then t3.level else null end as brandratio_unit_level
|
|
,case
|
|
when t4.PACK_COD is not null then t4.level
|
|
when t5.CMPS_COD is not null then t5.level else null end as brandratio_countingunit_level
|
|
|
|
from all_pack_pack_property t1
|
|
--unit by Pack
|
|
left join (select * from brand_ratio where upper(type) = 'UNIT' and upper(Level) = 'PACK') t2
|
|
on t1.PACK_COD = t2.pack_cod
|
|
and t1.MARKET = t2.market
|
|
--unit by MOLECULE
|
|
left join (select * from brand_ratio where upper(type) = 'UNIT' and upper(Level) = 'MOLECULE') t3
|
|
on t1.CMPS_COD = t3.cmps_cod
|
|
and t1.MARKET = t3.market
|
|
--PDOT by Pack
|
|
left join (select * from brand_ratio where upper(type) = 'COUNTINGUNIT' and upper(Level) = 'PACK') t4
|
|
on t1.PACK_COD = t4.pack_cod
|
|
and t1.MARKET = t4.market
|
|
--PDOT by MOLECULE
|
|
left join (select * from brand_ratio where upper(type) = 'COUNTINGUNIT' and upper(Level) = 'MOLECULE') t5
|
|
on t1.CMPS_COD = t5.cmps_cod
|
|
and t1.MARKET = t5.market
|
|
--VALUE by Pack
|
|
left join (select * from brand_ratio where upper(type) = 'VALUE' and upper(Level) = 'PACK') t6
|
|
on t1.PACK_COD = t6.pack_cod
|
|
and t1.MARKET = t6.market
|
|
--VALUE by MOLECULE
|
|
left join (select * from brand_ratio where upper(type) = 'VALUE' and upper(Level) = 'MOLECULE') t7
|
|
on t1.CMPS_COD = t7.cmps_cod
|
|
and t1.MARKET = t7.market
|
|
)
|
|
select
|
|
MARKET
|
|
,PACK_COD
|
|
-- ,brandratio_value_level
|
|
-- ,brandratio_unit_level
|
|
,nvl(brandratio_countingunit_level,'Market') as brandratio_countingunit_level
|
|
from match_data
|
|
"
|
|
& UsingLimit,
|
|
null,
|
|
[
|
|
EnableFolding = true
|
|
]
|
|
)
|
|
in
|
|
Source
|
|
```
|
|
lineageTag: f3952339-ada3-47e3-8e8e-670264eff2ef
|
|
queryGroup: OLD
|
|
|
|
annotation PBI_NavigationStepName = Navigation
|
|
|
|
annotation PBI_ResultType = Table
|
|
|
|
expression Fact_Sales_SQL = ```
|
|
let
|
|
Source = "
|
|
select
|
|
DATA_SOURCE,
|
|
MARKET,
|
|
KEY_COMPETITOR,
|
|
CLASS,
|
|
YYYYMM,
|
|
PACK_COD,
|
|
AUDIT_COD,
|
|
VA,
|
|
UT,
|
|
CU,
|
|
PT,
|
|
SALES_UNIT_CAL,
|
|
SALES_UNIT_CAL_LY,
|
|
SALES_VALUE_CAL,
|
|
SALES_VALUE_CAL_LY,
|
|
CONUTING_UNIT,
|
|
CONUTING_UNIT_LY,
|
|
PDOT,
|
|
PDOT_LY,
|
|
PRESCRIPTION,
|
|
PRESCRIPTION_LY,
|
|
---关联主键-----------------------------
|
|
TO_DATE(CONCAT(YYYYMM, '01'), 'yyyyMMdd') AS DATE_KEY,
|
|
COALESCE(MARKET, '') || DATA_SOURCE AS MARKET_KEY,
|
|
COALESCE(PACK_COD, '') || DATA_SOURCE || NEW_CODE AS PACK_SOURCE,
|
|
COALESCE(AUDIT_COD, '') || DATA_SOURCE AS AUDIT_SOURCE,
|
|
COALESCE(AUDIT_COD, '') || DATA_SOURCE || REGION_TYPE AS AUDIT_KEY,
|
|
COALESCE(MARKET, '') || COALESCE(CLASS, '') || DATA_SOURCE AS CLASS_KEY,
|
|
|
|
COALESCE(STORE_TYPE, '') || DATA_SOURCE AS STORE_TYPE_SOURCE,
|
|
COALESCE(STORE_TYPE, '') || '-' || COALESCE(PLATFORM_TYPE, '') AS STORE_PLATFORM,
|
|
COALESCE(REIMBURSE_TYPE, '') || DATA_SOURCE AS REIMBURSETYPE_SOURCE,
|
|
COALESCE(REIMBURSE, '') || DATA_SOURCE AS REIMBURSE_SOURCE,
|
|
COALESCE(PRESCRIPTION_TYPE, '') || DATA_SOURCE AS PRESCRIPTION_SOURCE,
|
|
COALESCE(PLATFORM_TYPE, '') || DATA_SOURCE AS PLATFORM_TYPE_SOURCE,
|
|
COALESCE(dept_name, '') || DATA_SOURCE AS DEPT_SOURCE,
|
|
COALESCE(AUDIT_COD, '') || DATA_SOURCE AS INST_SOURCE,
|
|
COALESCE(AIA_HP_FLAG, '') || DATA_SOURCE AS HP_SOURCE,
|
|
-------------------------------------
|
|
--Retail藏数逻辑标签------------------
|
|
PACK_FLAG,
|
|
PROD_FLAG,
|
|
DTP_FLAG,
|
|
CMPS_FLAG,
|
|
-------------------------------------
|
|
--EC数据标签--------------------------
|
|
PLATFORM_TYPE,
|
|
STORE_NAME,
|
|
STORE_TYPE,
|
|
-------------------------------------
|
|
--COUNTY数据标签----------------------
|
|
REGION_TYPE,
|
|
--AIA数据标签-------------------------
|
|
INST_CODE,
|
|
AIA_HP_FLAG,
|
|
AIA_REMOVE,
|
|
-------------------------------------
|
|
--XIE HE 数据标签---------------------
|
|
NEW_CODE,
|
|
DEPT_NAME,
|
|
H_LEVEL,
|
|
REIMBURSE,
|
|
REIMBURSE_TYPE,
|
|
PRESCRIPTION_TYPE,
|
|
-------------------------------------
|
|
--Merged Data部分--------------------
|
|
MERGEDATA_FLAG,
|
|
MERGEDATA_FLAG_MKT,
|
|
MERGEDATA_FLAG_CHPA_DTP,
|
|
MERGEDATA_FLAG_DTP_NOROC,
|
|
MERGED_DATA_DTP_OTHERS,
|
|
TARGET_INS,
|
|
-------------------------------------
|
|
NULL AS CORP_COD
|
|
from
|
|
DM.DM_TF_EXT_UNIONALL_SALES_MAPPING
|
|
"
|
|
in
|
|
Source
|
|
```
|
|
lineageTag: 497f395d-d390-4732-9549-1d1416916ed3
|
|
queryGroup: Fact_Sales
|
|
|
|
annotation PBI_NavigationStepName = Navigation
|
|
|
|
annotation PBI_ResultType = Text
|
|
|