Search code examples
reporting-servicesssrs-2008ssrs-tablix

Display previous month AND year ssrs report


I am trying to figure out how to code an expression to display the previous month for a date entered. So if 08/01/2023 is entered, I need it to show July 2023.

It works fine, except if the date entered is 1/1/2023. It returns December 2023.

I can't figure how how to put the expression together with the iif statement so if the month entered is 1 (January) subtract 1 from the year and return the previous year. Otherwise, display the previous month and current year.

So.
08/01/2023 - Returns July 2023 01/01/2023 - returns December 2022

I have tried several different command combinations and it just keeps erroring. Any help would be great!! Thank you in advance Christine


Solution

  • What you want to do is to subtract a month first from your date, and then get the Month name from it and concat it to the Year.

    Try this expression - obvioulsy substitute the field with the appropriate field value.

    =MonthName(Month((DateAdd("m",-1,Parameters!test.Value)))) & " " +cstr(year((DateAdd("m",-1,Parameters!test.Value))))