我正在尝试制作Power Pivot报告。 在报告中,我有5个相同层次结构的实例,这些实例命中了不同FK上的Fact表。 例如。基本层次结构是与父子相关的组织单位层次结构。 结构:
NodeKey | Node | Parent |
------------------------------------------
1 | Accountant | Finance |
2 | Finance | Central Admin. |
2 | Italy-Branch | EU Cost Center |
它以“所有者”,“记者”,“位置”,“关闭者”,“审阅者”的身份加入事实。
事实:
Fact Key | dwh_Owner_Key |dwh_Location_Key|
-------------------------------------------
1 | 1 | 2 |
2 | 1 | 2 |
NodeKey = dwh_Owner_Key
NodeKey = dwh_Location_Key
在我的Power Pivot模型中,我通过添加列来弄平了层次结构
HierarchyPath = PATH ( 'table name'[NodeKey]; 'table name'[ParentKey] )
HierarchyDepth = PATHLENGTH ( 'table name'[HierarchyPath] )
IsLeaf =CALCULATE (
COUNTROWS ( 'table name' );
ALL ( 'table name' );
'table name' [ParentKey] = EARLIER ( 'table name' [NodeKey] )
) = 0
Level1 =
LOOKUPVALUE (
'table name'[Name];
'table name'[NodeKey];
PATHITEM ( 'table name'[HierarchyPath]; 1; INTEGER )
)
Level2 - 10 (number of levels are fixed) = = IF (
'table name'[HierarchyDepth] >= 2;
LOOKUPVALUE (
'table name'[Name];
'table name'[NodeKey];
PATHITEM ( 'table name'[HierarchyPath]; 2; INTEGER )
);
'table name'[Level1]
)
上面的代码在层次结构的所有5个实例上完成。
就我而言,我已经通过事实表中添加的以下代码设法附加了一个层次结构
First i define Maximum Depth:
------------------------------------------------
MaxNodeDepthTableName2:=MAX ( 'table name'[HierarchyDepth] )
Then I check which Depth is browsed:
------------------------------------------------
BrowseDepthTableName1:=ISFILTERED ( 'table name'[Level1] )
+ ISFILTERED ( 'table name'[Level2] )
+ ISFILTERED ( 'table name'[Level3] )
+ ISFILTERED ( 'table name'[Level4] )
+ ISFILTERED ( 'table name'[Level5] )
+ ISFILTERED ( 'table name'[Level6] )
+ ISFILTERED ( 'table name'[Level7] )
+ ISFILTERED ( 'table name'[Level8] )
+ ISFILTERED ( 'table name'[Level9] )
+ ISFILTERED ( 'table name'[Level10] )
Then I calculate the measure:
------------------------------------------------
Total Count:=IF (
[BrowseDepthTableName1] > [MaxNodeDepthTableName2;
BLANK ();
SUM ( Fact[TotalCount] )
)
我的问题是: 如何将层次结构的其他4个实例添加到计算的度量中? DAX的外观如何?