Devin
Devin

Reputation: 1

SSRS Switch Function and date concatenation

I have a text field that I'm trying to condtionaly set. I'm new to SSRS and have not sued the Switch Function before. What I'm trying to do is use the function to give me the Month and then concatenate the year - 1 (so last year) to the end of the Month name. I have included the code that is working to give me the month, but I'm not sure how to get the year added to the end.

Thanks for any help.

=Switch(
Month(Today) = "1", "January",
Month(Today) = "2", "February",
Month(Today) = "3", "March",
Month(Today) = "4", "April",
Month(Today) = "5", "May",
Month(Today) = "6", "June",
Month(Today) = "7", "July",
Month(Today) = "8", "August",
Month(Today) = "9", "September",
Month(Today) = "10", "October",
Month(Today) = "11", "November",
Month(Today) = "12", "December"
)

Upvotes: 0

Views: 1892

Answers (2)

user359040
user359040

Reputation:

You could add & " " & (Year(Today)-1) to your existing expression, so that it becomes:

=Switch(
Month(Today) = "1", "January",
Month(Today) = "2", "February",
Month(Today) = "3", "March",
Month(Today) = "4", "April",
Month(Today) = "5", "May",
Month(Today) = "6", "June",
Month(Today) = "7", "July",
Month(Today) = "8", "August",
Month(Today) = "9", "September",
Month(Today) = "10", "October",
Month(Today) = "11", "November",
Month(Today) = "12", "December"
)
& " " & (Year(Today)-1)

However, it would generally be easier to set up an expression as

=DateAdd(DateInterval.Year,-1,Today())

(to get the corresponding date from a year ago), and then set the Format property (in the Properties window) to be MMMM yyyy.

Upvotes: 1

M.C.Rohith
M.C.Rohith

Reputation: 3750

use & symbol to concatenate the two String.

=Switch( Month(Today) = "1", "January", Month(Today) = "2", "February", Month(Today) = "3", "March", Month(Today) = "4", "April", Month(Today) = "5", "May", Month(Today) = "6", "June", Month(Today) = "7", "July", Month(Today) = "8", "August", Month(Today) = "9", "September", Month(Today) = "10", "October", Month(Today) = "11", "November", Month(Today) = "12", "December" ) & =Other Function.

Upvotes: 1

Related Questions