多个语句以防 MDX

Multiple statements in case MDX

我必须编写将显示在列上并将行分为三组的 MDX。第一组以数字区分,第二组以属性区分,第三组是休息不适合的地方。

到目前为止,我的代码看起来像这样:

case 
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "4254255527"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "2752637520"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "5637839739"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "9378793737"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "3789789397"  then "ABC"
    when [Document].[Document series].CURRENTMEMBER.MEMBERVALUE = "XYZ" then "XYZ"
    else "Rest"
end

但我每次都"Rest"。

我该如何纠正?

编辑: 再次尝试但仍然无效:

case 
    when [Customer].[Customer's Document].[&5196189651]  then "ABC"
    when [Customer].[Customer's Document].[&7885181585]  then "ABC"
    when [Customer].[Customer's Document].[&7511535861]  then "ABC"
    when [Customer].[Customer's Document].[&4742575277]  then "ABC"
    when [Customer].[Customer's Document].[&7272727272]  then "ABC"
    when [Customer's Document].[Document Series].[&CHP] then "XYZ"
    else "Rest"
end

您使用的是哪种 BI 工具;您可以将其添加到新列中作为数据源视图的名称计算(右键单击 Customer table->New Named Calculation->ColumnName:XXX)。 示例:

CASE 
    WHEN ACOLUMN BETWEEN 0 AND 10 THEN 'ABC'
    WHEN ACOLUMN BETWEEN 10 AND 20 THEN 'ABC'
    ELSE 'REST'
END

我相信在 CASE 中你必须使用相同的 hierarchy.Alternative 你可以将你的代码分成两部分:

case 
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "4254255527"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "2752637520"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "5637839739"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "9378793737"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "3789789397"  then "ABC"
    when [Document].[Document series].CURRENTMEMBER.MEMBERVALUE = "XYZ" then "XYZ"
    else "Rest"
end

CASE
when [Document].[Document series].CURRENTMEMBER.MEMBERVALUE = "XYZ" then "XYZ"
    else "Rest"
end

我感觉你更想做如下事情:

WITH 
  SET [ABC] AS 
    {
      [Customer].[Customer's Document].&[5196189651]
     ,[Customer].[Customer's Document].&[7885181585]
     ,[Customer].[Customer's Document].&[7511535861]
     ,[Customer].[Customer's Document].&[4742575277]
     ,[Customer].[Customer's Document].&[7272727272]
    } 
  MEMBER [Customer].[All].[ABC] AS 
    Aggregate([ABC]) 
  MEMBER [Customer].[All].[XYZ] AS 
    [Customer].[Customer's Document].[Document Series].&[CHP] 
  SET [REST] AS 
    Except
    (
      [Customer].[Customer's Document].MEMBERS
     ,[ABC]
    ) 
  MEMBER [Customer].[All].[Rest] AS 
    Aggregate([REST]) 
  SET [FINAL] AS 
    {
      [Customer].[All].[ABC]
     ,[Customer].[All].[XYZ]
     ,[Customer].[All].[Rest]
    } 
SELECT 
  [FINAL] ON 1
 ,{[Measures].[Amount]} ON 0
FROM [YourCube];

或者可能是以下内容:

WITH 
  SET [ABC] AS 
    {
      [Customer].[Customer's Document].&[5196189651]
     ,[Customer].[Customer's Document].&[7885181585]
     ,[Customer].[Customer's Document].&[7511535861]
     ,[Customer].[Customer's Document].&[4742575277]
     ,[Customer].[Customer's Document].&[7272727272]
    } 
  MEMBER [Customer].[All].[ABC] AS 
    Aggregate([ABC]) 
  MEMBER [Customer].[All].[XYZ] AS 
    [Customer].[Customer's Document].[Document Series].&[CHP] 
  SET [REST] AS 
    Except
    (
      [Customer].[Customer's Document].MEMBERS
     ,{
        [ABC]
       ,[Customer].[Customer's Document].[Document Series].&[CHP]
      }
    ) 
  MEMBER [Customer].[All].[Rest] AS 
    Aggregate([REST]) 
  SET [FINAL] AS 
    {
      [Customer].[All].[ABC]
     ,[Customer].[All].[XYZ]
     ,[Customer].[All].[Rest]
    } 
SELECT 
  [FINAL] ON 1
 ,{[Measures].[Amount]} ON 0
FROM [YourCube];

编辑

只是一个警告 - 在接受的答案中有以下 mdx:

case 
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "4254255527"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "2752637520"  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER.MEMBERVALUE = "5637839739"  then "ABC"
...
...

这可能被标记为解决方案,但不是很好 mdx。在这种情况下,应使用 IS 运算符:

case 
    when [Customer].[Customer's Document].CURRENTMEMBER IS 
             [Customer].[Customer's Document].[Customer's Document].&[4254255527]  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER IS 
             [Customer].[Customer's Document].[Customer's Document].&[2752637520]  then "ABC"
    when [Customer].[Customer's Document].CURRENTMEMBER IS 
             [Customer].[Customer's Document].[Customer's Document].&[5637839739]  then "ABC"
...
...