用零替换空值

时间:2014-10-23 10:01:01

标签: reporting-services ssrs-2008-r2

我知道这个问题之前已被问过多次,但是按照之前的解决方案我还是无法解决问题:

我有一份SSRS(2008R2)报告,它以矩阵形式显示数据。有一个水平列组包含可能存在或不存在的值:当值不存在时,我想用0替换空单元格。目前报告呈现如下:

enter image description here

我希望那些空单元格中包含0。 细胞表达设定为:

 =Sum(Fields!number.Value)

所以我试过

 =iif (IsNothing(Sum(Fields!number.Value)),0,Sum(Fields!number.Value))

=iif (IsNothing(Fields!number.Value),0,Sum(Fields!number.Value))

=iif (Sum(Fields!number.Value)>0,Sum(Fields!number.Value),0)

......但“空”单元仍然存在。我确定我做的事情很糟糕......但是什么?

编辑:为了更好地说明我的情况,我的查询产生的输出(在SSMS中)类似于:

File | outcomeID     | number
A    |    Outcome1   |   2
A    |    Outcome2   |   1
B    |    Outcome2   |   2
C    |    Outcome1   |   1
D    |    Outcome3   |   2

......这将产生SSRS的结果:

File | Outcome1 | Outcome2  | Outcome3
 A   |    2     |     1     |
 B   |    2     |           |
 C   |    1     |           |
 D   |          |           |    2

使用列组:

enter image description here enter image description here

即使我将表达式更改为:

=999

我最终得到了

File | Outcome1 | Outcome2  | Outcome3
 A   |    999   |     999   |
 B   |    999   |           |
 C   |    999   |           |
 D   |          |           |    999

......即很多空格。

EDIT2 我上传了一个非常小的示例.rdl文件[REMOVED],使用上面的示例数据 - 它再现了问题

2 个答案:

答案 0 :(得分:8)

我的第一个想法是对存储过程进行了更改,但由于我有一个类似的报告来快速测试某些内容,我有了一个想法。

试试这个

=0+Sum(Fields!number.Value)

答案 1 :(得分:1)

我倾向于使用以下内容(但在SSRS 2005上):=CInt(Fields!number.Value)。也可以使用其他转换,例如CDbl

或者,但是稍长一点,请尝试=IIf(Fields!number.Value Is Nothing, 0, Fields!number.Value)