Rolling 12 Months - with Financial Year / Month Slicer

Hi everyone, I have this code getting the rolling 12 months. However, I am having a hard time incorporating it having with the financial year and month slicer. Say, I selected FY23 and Oct, the calculation will be 12 months backwards. Showing future dates as well is killing me :grin: Here’s my code.

Rolling 12 Months = 
VAR EndDate =
    MAX( 'Date'[Date] )       -- retrieves MAX Date   
                
VAR StartDate =
    EDATE( EndDate, -12 ) + 1 -- shifts EndDate to year beginning
 
VAR Result =
    CALCULATE(
         [Total Sales By Team (Accounting) MTD],
         -- retrieves the relevant date range
         DATESBETWEEN( 'Date'[Date], StartDate, EndDate )
    )
RETURN
     Result

Found the answer here :slight_smile:

VAR LastDayAvailable =
    CALCULATE (
        MAX ( 'Invoice WIP Ledger Report'[Invoiced Date] ),
        ALL ( 'Invoice WIP Ledger Report' )
    )
VAR FirstDayInSelection =
    MIN ( 'Date'[Date] )
VAR ShowData = ( FirstDayInSelection <= LastDayAvailable )
VAR Result =
    IF (
        ShowData,
        CALCULATE (
            [Total Sales By Team (Accounting) MTD],
            DATESYTD ( 'Date'[Date], "30/6" )
        )
    )
RETURN
    Result