1
votes

I'm working in SSRS and I'm trying to create dynamic month and year header columns to look like this:

Oct 2015 | Nov 2015 | Dec 2015 | Jan 2016 | Feb 2016

The code I've tried is this:
=MONTHNAME(Today), TRUE) & " " & YEAR(Now)

This gives the desired result, and I know if I do +1, it'll go to the next month or year, but what happens when it turns January? How can I make sure next year's months have 2016?Is this possible? Not sure if I'm making sense on this, but I can clarify if needed.

Basically, I have 12 columns that have the months in them, and the column names will slowly move to the left. How can I make sure the year corresponds with the correct month when the year changes?

2
Is it something you're looking for? technet.microsoft.com/en-us/library/… You didn't specify how you're +1'ing your date.Evaldas Buinauskas
datepart will help youwiretext
I'm adding +1 to month. Here's an update of the code for when it is greater than 12: =MONTHNAME(IIF(MONTH(Today)+2>12,MONTH(Today)+2-12,MONTH(Today)+2), TRUE)Marco

2 Answers

0
votes

Never mind I found my answer. Here's my solution if anyone else needs it. What I had to do was another if statement when the month's value was greater than 12, add 1 to the year value. If it's not, it will default to the current year.

=MONTHNAME(IIF(MONTH(Today)+4>12,MONTH(Today)+4-12,MONTH(Today)+4), TRUE) & " " & IIF(MONTH(Today)+4>12,YEAR(NOW)+1,YEAR(NOW))

Thanks for the tips guys!

0
votes

Glad you were able to figure out a way.

There's more than one way to skin a tauntaun:

=MONTHNAME(DATEADD("M", 4, Today()), TRUE) & " " &
YEAR(DATEADD("M", 4, Today()))