Forum Discussion

Tlotly's avatar
Tlotly
Icon for Helper V rankHelper V
1 year ago
Solved

3 months view in a matrix

Good day   Is it possible to only show last 3 months on the matrix, based on a Period selection? For example, if I select 202508, I need the matrix to show, Aug 2025, Jul 2025 and Jun 2025.    ...
  • danextian's avatar
    1 year ago

    Hi Tlotly 

    You will need to use a disconnected table for the slicer and reference that in a measure.

     

    Replace the _XMonths value in the measure below.

    Total Revenue Last Six Months = 
    VAR _XMonths = 6
    VAR _EndDate =
        -- Get the latest selected date from the disconnected date slicer
        MAX ( DisconnectedDate[Date] )
    
    VAR _StartDate =
        -- Calculate the start date by subtracting 6 months from the end date
        -- and adding 1 day to make it an inclusive range (e.g., from 1st to 30th)
        EDATE ( _EndDate, -_XMonths ) + 1
    
    RETURN
        -- Calculate Total Revenue between the calculated start and end dates
        CALCULATE (
            [Total Revenue],
            -- Use KEEPFILTERS to retain any existing filters on Dates[Date]
            -- and apply the custom 6-month date range
            KEEPFILTERS ( Dates[Date] >= _StartDate && Dates[Date] <= _EndDate )
        )
    

     

    Please see the attached pbix.