2016-04-15 75 views
3

我必須編寫將顯示在列上的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 

但我發現了「休息」每次。

我該如何糾正?

編輯: 另一種嘗試,但仍無法正常工作:

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 
+0

什麼是客戶文檔的價值,關鍵和名稱屬性?客戶維度的結構是什麼?你如何查詢這項措施並將「休息」視爲最終結果?請將查詢添加到您的問題中,以便我們提供幫助。 – BICube

+0

@Dodzik - 在最終的SELECT子句的行上是Dimension [[Customer])?如果它不在行上,那麼Currentmember是所有成員....只有當維度實際上是_current_即在上下文中時,currentmember才起作用。這可能是你一直得到休息的原因。你可以添加你的mdx腳本的其餘部分嗎? – whytheq

回答

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

您的意思是在方括號[Customer]之外有'&'。[Customer's Document]。&[7272727272] – BICube

+0

@Ala我只是複製了原始問題的成員名稱,但是您是正確的'&'會通常在大括號之外。 – whytheq

+0

@Dodzik - 我有一種感覺,這是不正確的標記,因爲Proffesore的答案中的一般mdx不是很好 - 做這個't] .CURRENTMEMBER.MEMBERVALUE =「4254255527」'是使用'IS'運算符的糟糕替代方案 – whytheq

0

哪些是您使用BI工具;您可以將其作爲名稱計算添加到新列中(右鍵單擊客戶表 - >新命名計算 - >列名:XXX)。 例子:

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

我相信,在情況下,你必須使用相同的hierarchy.Alternative你可以打破你的代碼,以2個部分:

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