September 2, 2008 at 5:08 am
Can someone tell me if there is a bug/issue with the SSRS built in function MonthName
The following expression in the header of my report returns an error on the True Part, but not on the false part
IIF(Parameters!THE_MONTH.Value = 100," Year " , cstr(monthname(Parameters!THE_MONTH.Value)))
Basically i have a drill through report based on Months but with a total for which i pass the month in as 100
September 2, 2008 at 5:21 am
=IIF(cint(Parameters!THE_MONTH.Value) = 100, monthname(1) , monthname(Parameters!THE_MONTH.Value))
This also returns #error when Parameters!THE_MONTH.Value = 100, however if Parameters!THE_MONTH.Value is for example 10 'October' is returned
This does not make any sense
September 2, 2008 at 5:39 am
I have figured out how to do it using a work around.
it seems it must evaluate the expression from right to left
if i include a second Parameter called Month_NAME2 and set its default as
=IIF(Parameters!THE_MONTH.Value = 100,1,Parameters!THE_MONTH.Value)
Then my text box will look at MONTH_NAME2 which will either be 1-12 or 1
Work Around and SSRS seem to be 2 statements that go hand in hand
September 2, 2008 at 9:54 am
What you've run into is not necessarily an SSRS issue although it manifests itself there a lot. Especially when using IIF to catch divide by zero conditions.
The problem is with the IIF function in VB.net.
In BOL, under Visual Basic Language Reference - IIf Function
(http://msdn.microsoft.com/en-us/library/27ydhh0d(VS.71).aspx)
it offers the following remark,
"The expressions in the argument list can include function calls. As part of preparing the argument list for the call to IIf, the Visual Basic compiler calls every function in every expression. This means that you cannot rely on a particular function not being called if the other argument is selected by Expression."
So...what's happening is, regardless of your trying to condition away the erroneous 'MONTHNAME(100)' condition, the compiler still sees it and throws the #error.
The two most common workarounds are to either write a custom code function that accomplishes your end and then use it instead of the IIF or use a nested IIF in your 'false' condition. This second option works because the compiler does read from the most nested conditions outward.
Given what you're trying to accomplish, I suggest a third option. try using the SWITCH() function. If you go to the link above, a link for SWITCH can be found at the bottom under See Also.
HTH
[font="Comic Sans MS"]toolman[/font]
[font="Arial Narrow"]Numbers 6:24-26[/font]
October 29, 2008 at 12:01 pm
I, too, am getting #Error when running my report. I'm trying to get the name of the month and year to display in my header. The year part works, but somehow the MonthName function is not working.
=MonthName(Parameters!DateBegin.Value)
Is there a diff function I should be using?
thx.
October 29, 2008 at 1:01 pm
latingntlman (10/29/2008)
I, too, am getting #Error when running my report. I'm trying to get the name of the month and year to display in my header. The year part works, but somehow the MonthName function is not working.=MonthName(Parameters!DateBegin.Value)
Is there a diff function I should be using?
thx.
Take a look here to see if it gives you any clues.
http://msdn.microsoft.com/en-us/library/zxbsw165(VS.71).aspx
Another thought is you may need to break down your date value into month and year. Something like:
=MonthName(Month(Parameters!DateBegin.Value))
HTH
[font="Comic Sans MS"]toolman[/font]
[font="Arial Narrow"]Numbers 6:24-26[/font]
April 10, 2009 at 12:38 pm
Use
=MonthName(Month(Parameters!DateBegin.Value))
March 31, 2010 at 3:18 pm
=MonthName(Month(Parameters!DateBegin.Value))
This worked for me.
Thanks!
Ned
May 8, 2013 at 3:18 am
Problem With MonthName(10,True)
So Following is the workaround.
=Switch(Fields!rsmonth.Value=12,"DEC",
Fields!rsmonth.Value <= 0,"")
May 8, 2013 at 3:19 am
=Switch(Fields!rsmonth.Value=12,"DEC",Fields!rsmonth.Value <= 0,"")
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply