MDX中的多个语句

时间:2016-04-15 11:40:51

标签: sql-server mdx business-intelligence olap

我必须编写将在列上显示的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

但我每次都会“休息”。

我该如何纠正?

编辑: 另一个尝试,但仍然没有工作:

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

2 个答案:

答案 0 :(得分:1)

我觉得你想做更多类似的事情:

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

答案 1 :(得分:0)

您使用的是哪种BI工具;您可以将其添加到新列作为数据源视图的名称计算(右键单击Customer表 - > 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中你必须使用相同的层次结构。备选你可以将你的代码分解为两部分:

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