2016-06-14 107 views
1

我已經寫了下面的MDX查詢這裏我在做什麼嘗試獲得基於在IIF功能應用多個條件湯姆的結果:SUM和多個IIF功能狀況MDX

WITH 
    SET [kpi_study] AS 
    {[study].[study].[BHC June12]} 
    SET [geographic] AS 
    {[territory.market_hierarchy].[state].[MP]} 
    SET [brand] AS 
    {[brand.brand_hierarchy].[brand].[Gold Flake (Unspecified)]} 
    SET [edu12] AS 
    IIF 
    (
     'All' = 'All' 
    ,[education].[education].MEMBERS 
    ,[education].[education].[All] 
    ) 
    SET [town] as 
    IIF(
     'All' = 'All' 
     ,[territory.market_hierarchy].[town_class].MEMBERS 
     ,[territory.market_hierarchy].[town_class].[All] 
     ) 
    SET [occp] as 
    IIF(
     'All' = 'All' 
      ,[occupation].[occupation].MEMBERS 
      ,[occupation].[occupation].[All] 
     ) 
    MEMBER [Measures].[t] AS 
    SUM(([edu12],[town],[occp]),[Measures].[tom]) 
SELECT 
    NON EMPTY 
    {[Measures].[t]} ON COLUMNS 
FROM [funnel_analysis] 
WHERE 
    {[kpi_study]*[geographic]*[brand]} 

但收到的一些錯誤。對於單一的iif功能,它的工作正常,即:**(SUM([edu12],[Measures].[tom]))**無法找出我在哪裏做錯了多個。

+0

什麼是錯誤?代碼看起來不錯。 – SouravA

+0

@SouravA:執行查詢時出錯。請檢查服務器日誌或聯繫您的管理員!無法找到我在做錯的地方..你可以幫我 – sam140

+0

@meff:請告訴我任何想法我們如何解決這個問題 – sam140

回答

1

我會做一個明確的交叉連接。 也請擺脫你正在創建的那些單一成員自定義集 - 這不是標準做法 - 只要把它們直接放在你的WHERE條款中即可。

WITH 
    SET [edu12] AS 
    IIF(
    'All' = 'All' 
    ,{[education].[education].MEMBERS} 
    ,[education].[education].[All] 
    ) 
    SET [town] as 
    IIF(
     'All' = 'All' 
     ,{[territory.market_hierarchy].[town_class].MEMBERS} 
     ,[territory.market_hierarchy].[town_class].[All] 
    ) 
    SET [occp] as 
    IIF(
     'All' = 'All' 
     ,{[occupation].[occupation].MEMBERS} 
     ,[occupation].[occupation].[All] 
    ) 
    MEMBER [Measures].[t] AS 
    SUM(
     [edu12] 
     *[town] 
     *[occp] 
     ,[Measures].[tom] 
    ) 
SELECT 
    NON EMPTY 
    {[Measures].[t]} ON COLUMNS 
FROM [funnel_analysis] 
WHERE 
    (
    [study].[study].[BHC June12] 
    ,[territory.market_hierarchy].[state].[MP] 
    ,[brand.brand_hierarchy].[brand].[Gold Flake (Unspecified)] 
) 

我更願意嘗試類似的使用Aggregate如下:

WITH 
    MEMBER [education].[education].[All].[edu12] AS 
    AGGREGATE(IIF(
    'All' = 'All' 
    ,{[education].[education].MEMBERS} 
    ,[education].[education].[All] 
    )) 
    MEMBER [territory.market_hierarchy].[town_class].[All].[town] as 
    AGGREGATE(IIF(
     'All' = 'All' 
     ,{[territory.market_hierarchy].[town_class].MEMBERS} 
     ,[territory.market_hierarchy].[town_class].[All] 
    )) 
    MEMBER [occupation].[occupation].[All].[occp] as 
    AGGREGATE(IIF(
     'All' = 'All' 
     ,{[occupation].[occupation].MEMBERS} 
     ,[occupation].[occupation].[All] 
    )) 
    MEMBER [Measures].[t] AS 
    (
     [education].[education].[All].[edu12] 
     ,[territory.market_hierarchy].[town_class].[All].[town] 
     ,[occupation].[occupation].[All].[occp] 
     ,[Measures].[tom] 
    ) 
SELECT 
    NON EMPTY 
    {[Measures].[t]} ON COLUMNS 
FROM [funnel_analysis] 
WHERE 
    (
    [study].[study].[BHC June12] 
    ,[territory.market_hierarchy].[state].[MP] 
    ,[brand.brand_hierarchy].[brand].[Gold Flake (Unspecified)] 
) 

探索腳本示例 - 這是否給你你所期望?如果沒關係,請繼續閱讀更復雜腳本的其他部分:

WITH 
    SET [edu12] AS 
    IIF(
    'All' = 'All' 
    ,{[education].[education].MEMBERS} 
    ,[education].[education].[All] 
    ) 
SELECT 
    [edu12] ON ROWS, 
{[Measures].[tom]} ON COLUMNS 
FROM [funnel_analysis] 
WHERE 
    (
    [study].[study].[BHC June12] 
    ,[territory.market_hierarchy].[state].[MP] 
    ,[brand.brand_hierarchy].[brand].[Gold Flake (Unspecified)] 
) 
+0

非常感謝您的快速回復.i已經嘗試過,因爲您已經提到過查詢,但得到了錯誤的結果,不出所料.i我不確切地知道爲什麼我得到錯誤的結果 – sam140

+0

這裏,而不是**所有**如果我傳遞任何其他值,然後得到正確的結果。我不知道我到底在哪裏做錯了。請你幫我 – sam140

+0

@ sam140所以如果你離開爲''全部' ='全部'你得到一個錯誤,但是你做''''='blahblah''那麼沒關係? – whytheq