我正在寻找一个优雅的MDX表达式,它只对最后一级维度的元素求值:
我有一个度量M,我也有一个分层的父 - 子维U,它是非平衡树:
R -> ( M = R1 + R2 = 157 )
..R1 -> ( M = R11 + R12 = 150 )
...R11 -> ( M=R111 = 100 )
.....R111 -> M=100
...R12 -> M = 50
..R2 -> M = 7
我有一个包含此维度中的一些元素的集合:
S含有R11,R111,R12
现在我需要为U.currentMember取M值(即最后一级后代的总和)
我已经写过这个表达式,它可以工作,但也许它们是一种更优雅的写作方式:
with member measures.XX as
sum (
intersect(
[S],
Except(
descendants( [U].currentMember ),
existing( descendants( [U].currentMember ).item(0) )
)
)
,
[M]
)
select
measures.xx on columns
from [CUBE]
where [U].[R]
注意:此MDX不运行:
with member measures.XX as
sum (
intersect(
[S],
descendants( [U].currentMember )
)
,
[M]
)
select
measures.xx on columns
from [CUBE]
where [U].[R]
因为返回250只有150。
正确的结果是150:R11 + R12(因为R11包含在R11中)。
糟糕的结果是:250:' 100'值取两次R11 + R111。
最终解决方案:
with member measures.XX as
sum(
intersect (
descendants([U].currentMember,,leaves),
[S]
)
,
[M]
)
select
measures.XX on 0,
descendants( [Unitats].[Unitat].[All] ) on 1
from [C]
答案 0 :(得分:0)
不确定您想要计算什么,但我们假设[会员]是您要评估的成员:
我使用descendants,filter和isLeaf MDX functions:
Sum(
Filter( Descendants( [Member] ), isLeaf(Member_hierarchy.currentmember) )
,[M])
你要添加所有后代,包括它自己的叶子(没有孩子)。