Forum Discussion

rmeng's avatar
rmeng
Icon for Helper II rankHelper II
5 years ago

Display Last N Values when selected Slicer

I need a matrix that display the last 6 MonthYear when selected. The formula gives me the totals by column and not by row and I need them.

Can you help me with the formula below to give me too the totals by row.

Note: I´ve created a secondary calendar (Presentation Calendar) to help me with the formula.

Focusedlast6Months=

    VAR CurrentDate =

        MAX ( 'DIM Calendar'[date] )

    VAR PreviousDate =

        EOMONTH ( CurrentDate-6 )

    VAR Result =

        IF (

            HASONEVALUE ( 'Presentation Calendar'[MONTH_YEAR] )

                && MAX ( 'Presentation Calendar'[Date] ) <= CurrentDate

                && MIN ( 'Presentation Calendar'[Date] ) > PreviousDate,

            CALCULATE (

                'OVERALL&INTERACTIONS'[% Focused Average],

                FILTER (

                    ALL ( 'DIM Calendar'[MONTH_YEAR] ),

                    'DIM Calendar'[MONTH_YEAR] = VALUES ( 'Presentation Calendar'[MONTH_YEAR] )

                )

            ),

            BLANK ()

        )

    RETURN

        Result

Thank you

2 Replies

    • rmeng's avatar
      rmeng
      Icon for Helper II rankHelper II

      Thanks for the video I´ve watched and created a formula, but still don´t work, April shouldn´t be there. If I select March 2021 the month year to be display should be  Mar2021, Feb2021,Jan2021, Dec2020, Nov2020, Oct2020.

      This is my formula but still don´t work:

      Last 6 Months =
      Var MaxDate = MAXX(ALLSELECTED('Presentation Calendar'),'Presentation Calendar'[DATE])
      Var MinDate = DATE(YEAR(MaxDate),MONTH(MaxDate)-6,DAY(MaxDate))
      Return
      CALCULATE( [% Focused Average],FILTER('DIM CALENDAR', 'DIM CALENDAR'[DATE] <= MaxDate && 'DIM CALENDAR'[DATE] >= MinDate))