MDX,删除ROWS上的零行

时间:2015-10-25 15:41:07

标签: mdx

我的MDX-Query看起来像这样:

WITH 
MEMBER [YEAR].[A2014_1-12] AS 
  ([YEAR].[2014], [TYPE].[ACTUAL]), 
MEMBER [YEAR].[P2014_1-12] AS 
  ([YEAR].[2014], [TYPE].[PLAN]),                           
MEMBER [YEAR].[P2015_1-12] AS 
  ([YEAR].[2015], [TYPE].[PLAN]),                          
MEMBER [YEAR].[A2015_YTD] AS 
  SUM(
    {[YEARPERIOD].[201501]:[YEARPERIOD].[201509]}
    ,(
     [Measures].currentmember
    ,[TYPE].[ACTUAL]
     )
   )                                           
SELECT 
{
[YEAR].[A2014_1-12],
[YEAR].[P2014_1-12],
[YEAR].[P2015_1-12],
[YEAR].[A2015_YTD]
}             
ON COLUMNS,
NON EMPTY 
 [COST_CENTER]
 *[COST_ELEMENT] ON ROWS 
FROM [CUBE] 
WHERE ([Measures].[COSTS]);

查询本身正在运行。然而,它也返回了很多零行,我想摆脱这些零行。奇怪的是 - 如果我在COLUMNS轴上只放置一个成员(例如[年]。[A2014_1-12]),它不会返回任何零行。但是一旦我开始向COLUMN轴添加另一个MEMBER,它也会返回零行(看起来它忽略了我的CROSSJOIN中的NON EMPTY)。如何删除上述MDX-Query中的零行?

1 个答案:

答案 0 :(得分:0)

尝试此作为开始

WITH 
MEMBER [YEAR].[A2014_1-12] AS 
  iif(
    ([YEAR].[2014], [TYPE].[ACTUAL]) = 0
    ,null
    ,([YEAR].[2014], [TYPE].[ACTUAL])
  )
MEMBER [YEAR].[P2014_1-12] AS 
  iif(
    ([YEAR].[2014], [TYPE].[PLAN]) = 0 
    ,null
    ,([YEAR].[2014], [TYPE].[PLAN])
  )                                                    
SELECT 
NON EMPTY
{
[YEAR].[A2014_1-12],
[YEAR].[P2014_1-12]
}             
ON COLUMNS,
NON EMPTY 
 [COST_CENTER]
 *[COST_ELEMENT] ON ROWS 
FROM [CUBE] 
WHERE ([Measures].[COSTS]);

另外,您不需要在此定义中定义度量层次结构的当前成员:

MEMBER [YEAR].[A2015_YTD] AS 
  SUM(
    {[YEARPERIOD].[201501]:[YEARPERIOD].[201509]}
    ,(
     [Measures].currentmember
    ,[TYPE].[ACTUAL]
     )
   ) 

这就够了:

MEMBER [YEAR].[A2015_YTD] AS 
  SUM(
    {[YEARPERIOD].[201501]:[YEARPERIOD].[201509]}
    ,([TYPE].[ACTUAL])
   ) 

请改为尝试:

WITH 
MEMBER [YEAR].[A2014_1-12] AS 
  iif(
    ([YEAR].[2014], [TYPE].[ACTUAL]) = 0
    ,null
    ,([YEAR].[2014], [TYPE].[ACTUAL])
  )
MEMBER [YEAR].[P2014_1-12] AS 
  iif(
    ([YEAR].[2014], [TYPE].[PLAN]) = 0 
    ,null
    ,([YEAR].[2014], [TYPE].[PLAN])
  ) 
SET [X] AS
 NonEmtpy(
  [COST_CENTER]*[COST_ELEMENT],
  {[YEAR].[A2014_1-12],[YEAR].[P2014_1-12]}
)                                                   
SELECT 
NON EMPTY
{
[YEAR].[A2014_1-12],
[YEAR].[P2014_1-12]
}             
ON 0,
//NON EMPTY 
 [X] ON 1
FROM [CUBE] 
WHERE ([Measures].[COSTS]);