RDLC 表达式导致 #error [英] RDLC expression resulting in #error

查看:56
本文介绍了RDLC 表达式导致 #error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个小数字段,利润和收入.它们显示在 tablix 控件中,每个控件都有自己的列.在第三列中,我想将利润除以收入.当这些字段中的任何一个为零时的结果是#error,我猜这是由于除以零所致.我想出了以下表达式来解决这个问题:

I have two decimal fields, profit and revenue. They are displayed in a tablix control, each has their own column. In a third column, I want to divide profit by revenue. The result when either of those fields is zero is #error, this I'm guessing is due to the dividing by zero. I came up with the following expression to solve this:

=iif(Cint(Fields!revenue.Value) = 0 orelse cint(Fields!profit.Value) = 0 ,"",FormatPercent(Fields!profit.Value / Fields!revenue.Value,2))

该表达式仍会导致 #error.我做了一些测试并去掉了表达式的错误部分.表情是这样的:

That expression still results in #error. I did some testing and took out the false portion of the expression. The expression looked like this:

=iif(Cint(Fields!revenue.Value) = 0 orelse cint(Fields!profit.Value) = 0 ,"No","Divide")

运行该表达式时,原来有#error 的点现在显示No".这告诉我表达式像我期望的那样工作,但是为什么当我在 false 条件中添加除法时它会抛出 #error .它不应该触及表达式的那部分.任何帮助表示赞赏.我也尝试了 switch 语句,但结果是一样的.只要我在表达式中有除法,它就会抛出 #error.

When running that expression, the original spots that had #error, now show "No". That tells me that expression is working like I would expect, but why does it throw the #error when I add the division in the false condition. It should not be hitting that part of the expression. Any help is appreciated. I also tried a switch statement but the results were the same. It threw the #error anytime I had the division in the expression.

推荐答案

非常类似于:报告服务表达式在某些情况下会出错

IIF 评估所有参数.如果任何参数产生错误,那么整个函数都会抛出错误,而不管这三个参数中的哪一个应该被返回.

IIF evaluates all arguments. If any argument generates an error, then the entire function will throw an error, regardless of which of the three arguments should have been returned.

试试这个代码:

=iif(Cint(Fields!revenue.Value) = 0,"",FormatPercent(Fields!profit.Value / iif(Cint(Fields!revenue.Value) = 0, Fields!revenue.Value, 1 ),2))

这段代码有第二个 iif 来防止任何参数被零除.(我直接将代码编辑到浏览器中:它可能需要稍作调整.此外,您确实应该使用单元格或占位符属性将格式设置为百分比,而不是您的表达式.)

This code has a second iif that keeps any argument from ever dividing by zero. (I edited the code directly into browser: it may need minor tweaks. Also, you really should use cell or placeholder properties to format as a percent, not your expression.)

这篇关于RDLC 表达式导致 #error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆