Showing posts with label expressions. Show all posts
Showing posts with label expressions. Show all posts

Thursday, March 29, 2012

Error level and expressions

In a report, I have the expression :

=iif(Sum( Fields!X_A_1.Value)<>0,(Sum( Fields!X_A.Value)-Sum( Fields!X_A_1.Value))/Sum( Fields!X_A_1.Value),"NA")

This expression product the error

"The value expression for the textbox ‘textbox12’ contains an error: Attempted to divide by zero."

I think it's because reporting execute the expression
(Sum( Fields!X_A.Value)-Sum( Fields!X_A_1.Value))/Sum( Fields!X_A_1.Value)

even if X_A_1 is equal to 0.

I would like reporting to display NA and not "#Error" when X_A_1 = 0

Is there is a way to catch the error in reporting?

Is there is a way for reporting not to execute the expression

(Sum( Fields!X_A.Value)-Sum( Fields!X_A_1.Value))/Sum( Fields!X_A_1.Value)

when X_A_1 is equal to 0.

Sorry if my english is not very good

Note: IIF() is a function call and evaluates all arguments (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctiif.asp)

Instead of the pattern =IIF(Y=0, A, X/Y), use =IIF(Y=0, A, X / IIF(Y=0, 1, Y)) to avoid the division by zero.

-- Robert

Wednesday, March 21, 2012

Error in SSRS Expressions

I am having an expression which is supposed to give me the values selected in a multivalued input parameter. I have tried following options however everytime it gives me error. Could someone let me know what might be the issue here.

1. Expression: =Parameters!i_Category.Label

Output: The Value expression used in textbox ‘textbox47’ returned a data type that is not valid.

2. Expression: =Parameters!i_Category.Label.ToString()

Output: System.Object[]

3. Expression: =CStr(Parameters!i_Category.Label)

Output: Error: Conversion from type 'String()' to type 'String' is not valid.

Take a look at this link for more information about parameters and working with multi-valued parameters.

http://msdn2.microsoft.com/en-us/library/aa337292.aspx|||Thanks Ian. It helped me a lot.