在SSRS中做表达式计算时,除数为零情况如何处理?

0
在报表中做同比、环比,经常要考虑除数为零的情况,如下
=IIf(ReportItems!txtYear2.Value = 0,0,(ReportItems!txtYear3.Value - ReportItems!txtYear2.Value) / ReportItems!txtYear2.Value)
但是,SSRS的表达式计算好像是先计算值,再执行函数,结果总是显示错误号。此种情况如何处理?
 
尝试做如下处理,运行通过
=IIf(ReportItems!txtYear2.Value = 0,0,(ReportItems!txtYear3.Value - ReportItems!txtYear2.Value) / IIf(ReportItems!txtYear2.Value=0,1,0))
已邀请:
1

BIWORK - 热衷于微软BI技术,技术架构和解决方案! 2015-09-23 回答

最直接的自己写一个除数函数解决这个问题试试看看:
Report -> Report Properties -> Code:

Public Function Divide(ByVal first As Double, ByVal second As Double) As Double
If second = 0 Then
Return 0
Else
Return first / second
End If
End Function

=IIF(Fields!column2.Value = 0, 0, Code.Divide(Fields!column1.Value, Fields!column2.Value))
0

郑大鹏 2015-09-23 回答

这种情况最好就在查询里做出来
0

天桥下的郑成功 - Hadoop大数据开发工程师、数仓架构师、熟悉数据仓库设计、Hadoop、Spark、HBase、Hive、SSIS等开发 2015-09-23 回答

你在判断里的成功或者失败那里,再写一次如果为0怎么怎么做
它这个表达式比较麻烦

要回复问题请先登录注册