[英]How to fix the error dividing by zero in my expression in visual studio reports?
I created report in visual studio.The problem is with dividing by zero in total fields. 我在visual studio中创建了报告。问题是在总字段中除以零。 I have one column with value 00:03:15 and another column with 00:00:00 I want to sum these columns and want to show me average value from first and second column.
我有一列值为00:03:15,另一列有00:00:00我想对这些列求和,并希望显示第一列和第二列的平均值。 I used this expression ( formula ) in my case :
我在我的案例中使用了这个表达式(公式):
=Format(
TimeSerial(0,0,
Round(iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_INBOUND.Value/Fields!N_INBOUND.Value))
+
iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_HOLD.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_INBOUND.Value-Fields!N_TRANSFERS_TAKEN.Value),0))
+iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_CONSULT.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_CONSULT.Value-Fields!N_TRANSFERS_TAKEN.Value),0)))/count(Fields!PRESENTATION_NAME.Value))
, "HH:mm:ss")
I used this https://sqldusty.com/2011/08/01/ssrs-expression-iif-statement-divide-by-zero-error/ and looks like : 我使用了这个https://sqldusty.com/2011/08/01/ssrs-expression-iif-statement-divide-by-zero-error/ ,看起来像:
=Format(
TimeSerial(0,0,
Round(
iif(count(Fields!PRESENTATION_NAME.Value)=0,0,
(iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_INBOUND.Value/Fields!N_INBOUND.Value))
+
iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_HOLD.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_INBOUND.Value-Fields!N_TRANSFERS_TAKEN.Value),0))
+iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_CONSULT.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_CONSULT.Value-Fields!N_TRANSFERS_TAKEN.Value),0)))/iif(count(Fields!PRESENTATION_NAME.Value)=0,1,count(Fields!PRESENTATION_NAME.Value)) ) ) )
, "HH:mm:ss")
But shows me an ERROR.Anyone who know how to fix that? 但是给我看了一个ERROR.Anyone谁知道如何解决这个问题?
Your data is something like below, Correct me if I am wrong. 您的数据如下所示,如果我错了,请纠正我。 At the Bottom I have added Total for both columns.
在底部,我为两列添加了总计。
Note: You will have to take care of what type your column (T_INBOUND and N_INBOUND) return values. 注意:您必须注意列(T_INBOUND和N_INBOUND)返回值的类型。
Now to create a Total for T_INBOUND and N_INBOUND 现在为T_INBOUND和N_INBOUND创建一个Total
To add totals for a column group In the tablix data region row group area, right-click a cell in the column group area for which you want totals, then point to Add Total, and click Before or After.
添加列组的总计在Tablix数据区域行组区域中,右键单击要为其总计的列组区域中的单元格,然后指向“添加总计”,并单击“之前”或“之后”。
A new column outside the current group is added to the data region, and then a default total is added for each numeric field in the column.
将当前组外部的新列添加到数据区域,然后为列中的每个数字字段添加默认总计。 Link: https://docs.microsoft.com/en-us/sql/reporting-services/report-design/add-a-total-to-a-group-or-tablix-data-region-report-builder-and-ssrs?view=sql-server-2017
链接: https : //docs.microsoft.com/en-us/sql/reporting-services/report-design/add-a-total-to-a-group-or-tablix-data-region-report-builder-和SSRS?视图= SQL服务器-2017
Once you have Total you can create create a Cell Either next to your Total or below Total and add expression as below 获得总计后,您可以创建一个单元格,在总计或总计下方创建一个单元格并添加表达式,如下所示
IIF(IsNothing(Fields!Total_N_BOUND.Value) OR Fields!Total_N_BOUND.Value=0,0,
Fields!Total_T_BOUND.Value/Fields!Total_N_BOUND.Value)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.