Forum Discussion

cj_oat's avatar
cj_oat
Helper I
1 year ago
Solved

Question regarding SAMEPERIODLASTYEAR Logic

Hi guys,   I'm trying to use SAMEPERIODLASTYEAR to see selected week based on slicer for This Year (TY) and Last Year (LY), however, when I select the week, it seems to reflect in TY column only bu...
  • Jihwan_Kim's avatar
    1 year ago

    Hi,

    I am not sure if I understood your question correctly, but when searching for last year's same week number value, please try something like below.

     

     

     

     

    LY selected week sales: = 
    VAR _currentyear =
        MAX ( 'calendar'[Year] )
    VAR _lastyear = _currentyear - 1
    VAR _selectedweeknumber =
        MAX ( 'calendar'[Week number] )
    VAR _lastyearperiod =
        FILTER (
            ALL ( 'calendar' ),
            'calendar'[Year] = _lastyear
                && 'calendar'[Week number] = _selectedweeknumber
        )
    RETURN
        IF (
            HASONEVALUE ( 'calendar'[Year] ),
            CALCULATE ( [This year selected week sales:], _lastyearperiod )
        )