Forum Discussion

bradbel's avatar
bradbel
Frequent Visitor
8 months ago
Solved

SAMEPERIODLASTYEAR and Week Number Groupings/Calculations Not Returning Expected Result

I am currently trying to set up a bar and line chart showing CY and PY sales data, grouped into week numbers on the X axis. The issue is that the SAMEPERIODLASTYEAR function is returning the incorrec...
  • Praful_Potphode's avatar
    8 months ago

    Hi bradbel ,

     

    Try below:

    PY Sales (Week Match) = 
    VAR CurrentWeekNum = SELECTEDVALUE('Date'[WeekNum])
    VAR CurrentYear = SELECTEDVALUE('Date'[Year])
    
    RETURN
        CALCULATE(
            [Total Sales],
            ALL('Date'), -- Remove existing filters
            'Date'[Year] = CurrentYear - 1,
            'Date'[WeekNum] = CurrentWeekNum -- Forces Week 1 to match Week 1, ignoring 53rd weeks
        )

    this forces you to go to last year and apply the same weekfilter.

    Please give kudos or mark it as solution once confirmed.

     

    Thanks and Regards,

    Praful