首页 > 解决方案 > SSRS 中的计算

问题描述

我在下面的 SSRS 表达式中使用。基本上计算基于 SSRS 报告中的两个文本字段,如下所示。ReportItems!Amount6.Value如果没有价值或记录,我仍然会出错 。

=iif(reportitems!Amount.Value = 0 or reportitems!Amount6.Value = 0 or Len(reportitems!Amount.Value) <= 0 or Len(reportitems!Amount6.Value) <= 0, NOTHING, (ReportItems!Amount.Value - ReportItems!Amount6.Value) / ReportItems!Amount6.Value)

=iif(reportitems!Amount.Value = 0 or reportitems!Amount6.Value = 0 or Len(reportitems!Amount.Value) <= 0 or Len(reportitems!Amount6.Value) <= 0, NOTHING, (ReportItems!Amount.Value - ReportItems!Amount6.Value) / ReportItems!Amount6.Value)

标签: sqlreporting-services

解决方案


IIF 是一个函数,而不是流控制

所以每个参数都会被执行,如果你想有条件地除法,你必须在它为空或为零时将除法器设置为1,当除法器为空或为零时不返回任何内容,你也可以使用cdec(表达式)转换为十进制,这样你就不必处理什么都没有的情况

=iif(cdec(reportitems!Amount.Value) = 0 or cdec(reportitems!Amount6.Value) = 0 or Len(reportitems!Amount.Value) <= 0 or Len(reportitems!Amount6.Value) <= 0, NOTHING, (cdec(ReportItems!Amount.Value) - cdec(ReportItems!Amount6.Value)) / iif(cdec(ReportItems!Amount6.Value) == 0,1,cdec(ReportItems!Amount6.Value)))

推荐阅读