SSRS - 报表生成器中的IIF错误

时间:2018-01-11 21:22:11

标签: reporting-services null

我遇到了一个零除错误的问题,我已经完成了一半。

基本上我需要(EstimatedValuePlanned - EAC)/ EstimatedValuePlanned

我有以下内容,但是我仍然在某些地方获得#Error:

= IIF (Fields!EstimatedValuePlanned.Value = 0 , 0, 
Fields!EstimatedValuePlanned.Value - Fields!EAC.Value) 
/ 
SUM(Fields!EstimatedValuePlanned.Value)

我已经多次更改了代码,但我仍然得到错误或NaN

谢谢

2 个答案:

答案 0 :(得分:0)

IIF将始终评估函数的两个部分,因此当SUM(Fields!EstimatedValuePlanned.Value)为零时,即使不是将返回的内容,您也会收到错误。

尝试使用SWITCH语句。表达式返回SWITCH后,True停止。

像这样的东西

= SWITCH(
SUM(Fields!EstimatedValuePlanned.Value) = 0 , 0, 
True, (Fields!EstimatedValuePlanned.Value - Fields!EAC.Value) / SUM(Fields!EstimatedValuePlanned.Value)
)

True表达式的作用类似于else

使用示例进行更新 我创建了一个新报告添加了一个数据集,并将数据集查询设置为以下(仅生成一些虚拟数据)。

DECLARE @t TABLE (EVP float, EAC float)

INSERT INTO @t VALUES
(1,2),
(2,3),
(5,4),
(0,2),
(1,0),
(0,0)

SELECT * FROM @t

然后我添加了一个表,将第一列设置为EVP和EAC,并将第3列设置为表达式,如下所示。

=SWITCH (
Fields!EVP.Value = 0, 0
, True, (Fields!EVP.Value - Fields!EAC.Value) / Fields!EVP.Value
)

报告设计看起来像这样。

enter image description here

当它运行时,这就是结果......

enter image description here

尝试复制上述步骤,看看您是否可以先使用此方法,然后查看报告中的差异。

答案 1 :(得分:0)

我得到了它:

=IIF  (Fields!EstimatedValuePlanned.Value = 0 , 0, 
Fields!EstimatedValuePlanned.Value - Fields!EAC.Value) 
/ 
IIF(Fields!EstimatedValuePlanned.Value = 
0,1,Fields!EstimatedValuePlanned.Value)

谢谢你们两个

相关问题