sqlsql-serverreporting-servicesssrs-2017

SSRS Previous Month Name


I need to get the previous month's name. E.g.

January --> December
July --> June

I tried using this:

=IIF(MONTH(Globals!ExecutionTime) = 1, "DECEMBER", MONTHNAME(MONTH(Globals!ExecutionTime)-1))

But this returns #Error when it is January. I'm assuming it's because the right else section of the IIF is still being evaluated even though the first part of the IIF returns TRUE.

Is there a better way to do this?

I'm using Visual Studio 2017 to make my SSRS report.


Solution

  • You seem to be mixing up T-SQL and VB. You want to use the DateTime methods AddMonths and ToString provided:

    =Globals!ExecutionTime.AddMonths(-1).ToString("MMMM");