MDX 中的 SUM 和多个 IIF 函数条件

SUM and multiple IIF Function condition in MDX

我在下面编写了 MDX 查询,我正在做的是尝试根据 IIF 函数中应用的多个条件获取 tom 的结果:

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]}

但是得到一些 error.For 单个 iif 函数它工作正常,即:**(SUM([edu12],[Measures].[tom]))** 无法找出我在多个方面做错的地方。

我会进行显式交叉连接。 另外,请删除您正在创建的那些单一成员自定义集 - 这不是标准做法 - 只需将它们直接放在 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)]
  )