在MDX查询中组合度量和kpi目标时如何摆脱空单元格

时间:2017-02-12 21:15:54

标签: ssas mdx

我在MDX查询中遇到此问题,其中在向查询添加KPI目标,趋势和状态后,NON EMPTY子句无法正常工作。 基本查询如下所示

SELECT 
    NON EMPTY({[Measure1], [Measure2], KPIValue('MyKpi')}) 
    ON COLUMNS, 
    NON EMPTY [Dim Country].[Name].[Name].ALLMEMBERS ON ROWS 
FROM [BIA CO]

返回这样的东西,这很好:

            Measure1    Measure2        MyKpi
Canada      7977        4487            3231
USA         6           14              6
UK          442         1179            180

当我添加KPI目标,趋势和状态时出现问题:

SELECT 
NON EMPTY({[Measure1], [Measure2], KPIValue('MyKpi'), KPIGoal('MyKpi'), KPIStatus('MyKpi'), KPITrend('MyKpi')}) 
    ON COLUMNS, 
    NON EMPTY [Dim Country].[Name].[Name]ALLMEMBERS ON ROWS 
FROM [BIA CO]

返回类似的内容:

             Measure1   Measure2    MyKpi   MyKpi   Goal    MyKpi Status    MyKpi Trend
Mexico      (null)      (null)  (null)  40300   -1              -1
Cuba        (null)      (null)  (null)  40300   -1              -1
Canada      7977        4487    3231    40300   -1               1
Portugal    (null)      (null)  (null)  40300   -1              -1
China       (null)      (null)  (null)  40300   -1              -1
USA         6           14      6       40300   -1               1
UK          442         1179    180     40300   -1               1

除了目标,状态和趋势之外,如何除去所有带空值的行?

3 个答案:

答案 0 :(得分:0)

只需将Non-empty behavior添加到您的KPI即可。如果设置Measure1,则会过滤掉所有空元组。它将继承Measure1中的非空行为。您也可以在具有类似逻辑的行上返回以下集合(输出将是相同的):

NonEmpty([Dim Country].[Name].[Name].ALLMEMBERS,[Measures].[Measure1]) on rows

答案 1 :(得分:0)

我遇到了类似的问题,这就是我所做的。就我而言,我无法控制立方体设计。我不是专家,所以在使用之前请等待一些经验丰富的反馈。

WITH
    MEMBER [KPIValue(ReservaKPI)] as KPIValue('ReservaKPI')
    MEMBER [KPIGoal(ReservaKPI)] as CASE WHEN ISEMPTY([KPIValue(ReservaKPI)]) THEN NULL ELSE KPIGoal('ReservaKPI') END
    MEMBER [KPIStatus(ReservaKPI)] as CASE WHEN ISEMPTY([KPIValue(ReservaKPI)]) THEN NULL ELSE KPIStatus('ReservaKPI') END
    MEMBER [KPITrend(ReservaKPI)] as CASE WHEN ISEMPTY([KPIValue(ReservaKPI)]) THEN NULL ELSE KPITrend('ReservaKPI') END
SELECT 
    NON EMPTY({[Cant Adultos], [Cant Noches], [KPIValue(ReservaKPI)], [KPIGoal(ReservaKPI)], [KPIStatus(ReservaKPI)], [KPITrend(ReservaKPI)]}) 
    ON COLUMNS, 
    NON EMPTY [Dim Mun].[NOMBRE].[NOMBRE].ALLMEMBERS ON ROWS 
FROM [BIA CO]

答案 2 :(得分:0)

我有时喜欢使用这样的HAVING子句:

SELECT 
  NON EMPTY 
    {
      [Measure1]
     ,[Measure2]
     ,KPIValue('MyKpi')
     ,KPIGoal('MyKpi')
     ,KPIStatus('MyKpi')
     ,KPITrend('MyKpi')
    } ON COLUMNS
 ,NON EMPTY 
    [Dim Country].[Name].[Name].ALLMEMBERS HAVING 
  (NOT IsEmpty([Measure1])) AND (NOT IsEmpty([Measure2])) ON ROWS
FROM [BIA CO];

但你可以按照@ user1998299的建议将该逻辑转移到WITH子句中 - 我可能会做一个自定义集:

WITH 
  SET [SmallSet] AS 
    NonEmpty
    (
      NonEmpty
      (
        [Dim Country].[Name].[Name].ALLMEMBERS
       ,[Measure1]
      )
     ,[Measure2]
    ) 
SELECT 
  NON EMPTY 
    {
      [Measure1]
     ,[Measure2]
     ,KPIValue('MyKpi')
     ,KPIGoal('MyKpi')
     ,KPIStatus('MyKpi')
     ,KPITrend('MyKpi')
    } ON COLUMNS
 ,NON EMPTY 
    [SmallSet] ON ROWS
FROM [BIA CO];