1
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...

但它不起作用。

4

1 回答 1

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查看输出的每一行并返回当前成员,但在上面您的行上没有此层次结构......所以 currentmember 是 All 成员,所以您的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

于 2015-11-18T21:24:48.817 回答