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

时间:2016-06-14 07:55:08

标签: mdx olap iif-function

我在下面写了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]}

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

1 个答案:

答案 0 :(得分:1)

我会做一个明确的交叉连接。 另外,请删除您正在创建的单个成员自定义集 - 这不是标准做法 - 只需将它们直接放在Get-Content 'D:\Websites.txt' | Select-Object @{n='Type';e={$_}}, @{n='Base';e={'IIS'}}, @{n='Status';e={'Monitored'}} | Export-Csv 'D:\test.csv' -NoType 子句中。

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