with member test as
case
when ([All Products].[All Products].[Group 2].&[1],[Measures].[minus-prod-trx])>0
then (ancestor([All Products].[All Products].[Group 2].&[1],2),[Measures].[minus-prod-trx])
when ([All Products].[All Products].[Group 2].&[2],[Measures].[minus-prod-trx])>0
then (ancestor([All Products].[All Products].[Group 2].&[2],2),[Measures].[minus-prod-trx])
end
问题:如果两个条件满足,我怎样才能得到两个值?现在只有一个结果返回,但两个条件都满足。我尝试过:
case
when [All Products].[Group 2].CURRENTMEMBER IS [All Products].[Group 2].&[1]
then...
但它不起作用。
答案 0 :(得分:0)
假设此层次结构为ON ROWS
:
[All Products].[All Products]
然后如下:
WITH MEMBER [Measures].test AS
CASE
WHEN
[All Products].[All Products].CURRENTMEMBER
IS [All Products].[All Products].[Group 2].&[1]
AND [Measures].[minus-prod-trx] > 0
THEN
(ancestor([All Products].[All Products].[Group 2].&[1],2),[Measures].[minus-prod-trx])
WHEN
....
以上是针对MS的AdvWrks多维数据集的上述示例:
WITH
MEMBER [Measures].test AS
CASE
WHEN
[Product].[Product Categories].CurrentMember
IS
[Product].[Product Categories].[Product].[Hitch Rack - 4-Bike]
AND
[Measures].[Internet Sales Amount] > 0
THEN
(
Ancestor
(
[Product].[Product Categories].[Product].[Hitch Rack - 4-Bike]
,2
)
,[Measures].[Internet Sales Amount]
)
WHEN
[Product].[Product Categories].CurrentMember
IS
[Product].[Product Categories].[Product].[Road Bottle Cage]
AND
[Measures].[Internet Sales Amount] > 0
THEN
(
Ancestor
(
[Product].[Product Categories].[Product].[Road Bottle Cage]
,3
)
,[Measures].[Internet Sales Amount]
)
END
SELECT
NON EMPTY
{
[Measures].[Internet Sales Amount]
,[Measures].test
} ON 0
,[Product].[Product Categories].[Product] ON 1
FROM [Adventure Works];
结果如下:
在评论中你提出以下内容
with member [Measures].Test as
case
when [Dim Date].[Hierarchy].currentmember
IS [Dim Date].[Hierarchy].[Calendar Year].&[2007].&[1].&[2]
then (ancestor([Dim Date].[Hierarchy].[Calendar Year].&[2007].&[1].&[2],2),[Measures].[Amount]) end
select {[Measures].Test} on 0
from [My Adventure Works];
此代码对我来说没问题。 [Dim Date].[Hierarchy].currentmember
不等于您在上面指定的成员 - currentmember
查看输出的每一行并返回当前成员但在上面您的行上没有此层次结构。因此,当前成员是所有成员,因此您的WHEN
条件为假。
Sourav通过创建上下文为您修复了上述内容,以便currentmember返回层次结构的All
成员以外的成员:
with member [Measures].Test as
case
when [Dim Date].[Hierarchy].currentmember
IS [Dim Date].[Hierarchy].[Calendar Year].&[2007].&[1].&[2]
then (ancestor([Dim Date].[Hierarchy].[Calendar Year].&[2007].&[1].&[2],2),[Measures].[Amount]) end
select
{[Measures].Test} on 0,
[Dim Date].[Hierarchy].[Calendar Year].&[2007].&[1].&[2] on 1 //<<including this means that the currentmember has something to work with!!
from [My Adventure Works];
请阅读currentmember函数的定义:https://msdn.microsoft.com/en-us/library/ms144948.aspx