RDLC 表达式导致#error
我有两个小数字段:利润和收入。它们显示在 Tablix 控件中,每个控件都有自己的列。在第三列中,我想将利润除以收入。当这些字段中的任何一个为零时,结果是#error,我猜测这是由于除以零造成的。我想出了以下表达式来解决这个问题:
=iif(Cint(Fields!revenue.Value) = 0 orelse cint(Fields!profit.Value) = 0 ,"",FormatPercent(Fields!profit.Value / Fields!revenue.Value,2))
该表达式仍然会导致#error。我做了一些测试并去掉了表达式中错误的部分。该表达式如下所示:
=iif(Cint(Fields!revenue.Value) = 0 orelse cint(Fields!profit.Value) = 0 ,"No","Divide")
运行该表达式时,原来有#error 的位置现在显示“否”。这告诉我表达式的工作方式正如我所期望的那样,但是为什么当我在错误条件下添加除法时它会抛出#error。它不应该击中表达式的那部分。任何帮助表示赞赏。我也尝试了 switch 语句,但结果是一样的。每当我在表达式中进行除法时,它就会抛出#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))
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")
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
非常类似于:
Reporting Services 表达式在某些情况下会出错
IIF 评估所有参数。如果任何参数生成错误,则整个函数都会抛出错误,无论应该返回三个参数中的哪一个。
试试这个代码:
这个代码有第二个 iif,可以防止任何参数被零除。
(我直接将代码编辑到浏览器中:它可能需要进行一些细微的调整。此外,您确实应该使用单元格或占位符属性将格式设置为百分比,而不是表达式。)
Very similar to:
Reporting Services expression gives error in some circumstances
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.
Try this code:
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.)
请注意,
您似乎无法在报表 iif 表达式中使用不受支持的数据类型。
这就是我所拥有的:
当“MyNotSoComplexObject”为空时,一切正常,当它被分配给某些东西时,我遇到了#error。
我通过尝试在报告中直接显示“MyNotSoComplexObject”发现了这一点。
我的工作是在我的数据集中放置一个布尔值,以验证“MyNotSoComplexObject”是否具有值。
Watch out,
It seem like you can't use unsupported Datatype in a report iif expression.
here is what I had:
When "MyNotSoComplexObject" was null everything was working, when it was assign at something, I had #error.
I discovered this by trying to display directly "MyNotSoComplexObject" in the report.
My work arround was to put a bool value in my dataset that verify if "MyNotSoComplexObject" has value.