在浏览器SSAS MDX中跨越度量时,将NULL值替换为0

时间:2017-05-22 10:50:37

标签: sql-server ssas mdx

我想在多维数据集中浏览时替换Null值,当我执行IIF或合并时,我会获得没有数据的所有空值(所有维度行),我只想为当前数据替换null交叉。这是一个解释更多的例子:

Year   Measure 1     Measure 2
2015     55            60
2016     44            70
2017      30           (null)

使用ISEMPTY OR COALESCE时的问题行为

Year Measure 1 Measure 2 (All TimeDim years) 0 0 2012 0 0 2013 0 0 2014 0 0 2015 55 60 2016 44 70 2017 30 0

现在数据集更大,无用值。

我想要的是什么:

Year Measure 1 Measure 2 2015 55 60 2016 44 70 2017 30 0

如何解决这个问题?谢谢。

2 个答案:

答案 0 :(得分:0)

您可以将IS运算符与NULL引用一起使用。 See here

另一种选择是将其包装在IIF语句中。 See here

答案 1 :(得分:0)

这是人们可以玩的例子:

SELECT 
  {
    [Measures].[Internet Sales Amount]
   ,[Measures].[Reseller Sales Amount]
  } ON COLUMNS
 ,NON EMPTY 
    [Date].[Calendar Year].[Calendar Year].MEMBERS ON ROWS
FROM [Adventure Works]
WHERE 
  [Geography].[Geography].[Country].&[Australia];

结果:

enter image description here

这是导致行扩展的简单修正:

WITH 
  MEMBER [Measures].[Reseller Sales Amount NEW] AS 
    IIF
    (
      [Measures].[Reseller Sales Amount] = 0
     ,0
     ,[Measures].[Reseller Sales Amount]
    ) 
SELECT 
  {
    [Measures].[Internet Sales Amount]
   ,[Measures].[Reseller Sales Amount NEW]
  } ON COLUMNS
 ,NON EMPTY 
    [Date].[Calendar Year].[Calendar Year].MEMBERS ON ROWS
FROM [Adventure Works]
WHERE 
  [Geography].[Geography].[Country].&[Australia];

结果

enter image description here

所以我们可以稍微修改一下新措施:

WITH 
  MEMBER [Measures].[Reseller Sales Amount NEW] AS 
    IIF
    (
        [Measures].[Reseller Sales Amount] = 0
      AND 
        [Measures].[Internet Sales Amount] <> 0
     ,0
     ,[Measures].[Reseller Sales Amount]
    ) 
SELECT 
  {
    [Measures].[Internet Sales Amount]
   ,[Measures].[Reseller Sales Amount NEW]
  } ON COLUMNS
 ,NON EMPTY 
    [Date].[Calendar Year].[Calendar Year].MEMBERS ON ROWS
FROM [Adventure Works]
WHERE 
  [Geography].[Geography].[Country].&[Australia];

然后我们有:

enter image description here

BE AWARE ...摆脱多维数据集空间内的空值会严重降低mdx脚本的性能,因此请小心使用以上内容 - 更好的是不要打扰上面的内容并在客户端中使用mdx做的转换(null)=&gt; 0