Question

I am having a really strange error when using the iif() statement in SSRS 2012.

I am trying to choose to print the name of a month whenever a month value is not equal to 99, and when it is equal to 99, I would like to print the string "Y.T.D" I was trying to achieve this using the statement:

=iif(Fields!Month.Value = 99, "Y.T.D", MonthName(Fields!Month.Value, true) )

Whenever I try to use this MonthName() function the months are printed correctly but the 99 field returns as "#error". This statement works fine when I leave the month as an integer or if I simply put in a dummy string, and I have already tried casting the MonthName() as a string (eg. "cStr(MonthName())").

Any ideas???

Was it helpful?

Solution

To answer my own question/to quote another answer I recieved from Syed Qazafi Anjum on Microsoft's forum:

=iif(Fields!Month.Value=99,"Y.T.D",monthname(iif(Fields!Month.Value<=12,Fields!Month.Value,12),true))

As taken from: http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/d484d8d4-3809-4850-ada6-8cac1239bfce/

OTHER TIPS

The MonthName function gets evaluated even when the month number is 99. Use switch instead of iif to fix this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top