在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))
=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))
没有找到相关结果
重要提示:提问者不能发表回复,可以通过评论与回答者沟通,沟通后可以通过编辑功能完善问题描述,以便后续其他人能够更容易理解问题.
3 个回复
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))
郑大鹏 2015-09-23 回答
赞同来自:
天桥下的郑成功 - Hadoop大数据开发工程师、数仓架构师、熟悉数据仓库设计、Hadoop、Spark、HBase、Hive、SSIS等开发 2015-09-23 回答
赞同来自:
它这个表达式比较麻烦