SSRS - [rsRuntimeErrorInExpression] The Value expression for the textrun ‘Textbox1.Paragraphs[0].TextRuns[0]’ contains an error: Argument 'Month' is not a valid value

Have you ever experienced this warning and error in expression while using IIF in the expression

Warning 1 [rsRuntimeErrorInExpression] The Value expression for the textrun ‘Textbox1.Paragraphs[0].TextRuns[0]’ contains an error: Argument 'Month' is not a valid value.

Let us see why this warning and error occurs and how to overcome it.

For this example,I have created report with parameter of data type Integer and then textbox with following expression :

=IIF(Parameters!Month.Value=0,"Invalid Month Value",MonthName(Parameters!Month.Value))

So if you pass 5,it will return month name for value 5 as shown below :


If you  pass 0 it should return "Invalid Month Value" but you will notice error and warning as shown below :



 The reason for error & warning is

If you pass 0,it becomes like below
=IIF(0=0,"Invalid Month Value",MonthName(0))

In IIF eventhough it returns True or False part based on condition,it will evaluate both True and False part as shown in above example.

Change the textbox expression like shown below :

=IIF(Parameters!Month.Value=0,"Invalid Month Value",MonthName(IIF(Parameters!Month.Value=0,1,Parameters!Month.Value)))

Now pass 0 ,report will run without any error as shown below :





 

3 comments:

kapsiii said...

Thanks. Its work..........

kapsiii said...

Thanks.its work..............

kapsiii said...

Thanks.......Its work......