Forum Discussion

texasbiuser's avatar
texasbiuser
Frequent Visitor
6 years ago
Solved

Display Current/Previous/Previous-Previous Month Name

Simple question today. I am formatting a report and have the need to display the Current month name, previous month name, and month prior to that. (Ie. January, February, March). This is to compare the 3 months data. I have already built the data for the months, but am having trouple coding the correct measure for just the month date themselves.

 

MonthName = FORMAT(DATE(2016,Table1[MonthNumber],1),"MMMM" -3)

 I've tried several variotions of the above code, but obviously doesn't work for me. I need a measure that works with a -1, -2, -5, etc. so that I can ad hoc display the month name minus X months from todays date.

  • Hi texasbiuser ,

     

    Try this:

    MonthName -3 = FORMAT ( DATE ( 2016, Table1[MonthNumber] - 3, 1 ), "MMMM" )

     

    Best Regards,

    Icey

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

2 Replies

  • You are doing the -3 on the name of the month (eg. "May") which does not make sense. You probably just need to do the -3 on the month number. Note: I'm also using the SELECTEDVALUE function to check that there is a single filter on the [Mth] column.

     

    Mth -3 = 
    VAR _SelectedMth = SELECTEDVALUE('Table1'[Mth])
    RETURN IF( ISBLANK(_SelectedMth), "n/a", FORMAT( date(2016,_SelectedMth-3,1), "MMM"))
  • Icey's avatar
    Icey
    Community Support

    Hi texasbiuser ,

     

    Try this:

    MonthName -3 = FORMAT ( DATE ( 2016, Table1[MonthNumber] - 3, 1 ), "MMMM" )

     

    Best Regards,

    Icey

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.