2016-06-14 44 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