RDLC expression leading to #error

I have two decimal fields, profit and income. They appear in the tablix control, each of which has its own column. In the third column, I want to divide earnings by income. The result, when any of these fields is zero, is #error, I assume this is due to division by zero. To solve this problem, I came up with the following expression:

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

This expression still leads to #error. I did some testing and took out the false part of the expression. The expression looked like this:

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

When running this expression, the C # error source points now show "No." This tells me that the expression works as I expected, but why does it throw #error when adding a division to a false state. He must not beat this part of the expression. Any help is appreciated. I also tried the switch statement, but the results were the same. He threw #error anytime I had a division in an expression.

+3
source share
2 answers

Very similar to: Reporting Services expression gives an error in some circumstances

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

Try this code:

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

iif, . ( : , . , , .)

+10

,

, iif .

:

=IIf(Fields!MyNotSoComplexObject.Value is nothing, "No object", Fields!MyOtherField.Value )

"MyNotSoComplexObject" null, , -, #error.

, "MyNotSoComplexObject" .

arround , bool , , "MyNotSoComplexObject" .

+1

All Articles