Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
cj_oat
Helper I
Helper I

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 but not in LY column as screenshot below (example here is I selected week 4)

 

I am trying to ensure that LY Week Selected also shows the number that is filtered in "Week" Slicer (or Max number of week if multiple weeks are selected in Slicer)

 

 

TY Week Selected = 
if(ISFILTERED('Calendar Table'[Week Number]),MAX('Calendar Table'[Week Number]),MAX('Sales Table'[Latest Week Number]))
LY Week Selected = CALCULATE([Dummy Value],SAMEPERIODLASTYEAR('Calendar Table'[Date]))

 

cj_oat_0-1737690733707.png

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

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.

Jihwan_Kim_1-1737694189619.png

 

 

Jihwan_Kim_0-1737694155246.png

 

 

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 )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

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.

Jihwan_Kim_1-1737694189619.png

 

 

Jihwan_Kim_0-1737694155246.png

 

 

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 )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
shivamdubey
New Member

Below measure will give you selected week from slicer and if not selected then you can return the max value of the table. In your case it is sales table
Selected_Week = IF(ISFILTERED('Table'[Week Number]),SELECTEDVALUE('Table'[Week Number]),MAX('Table'[Week Number]))
 
Below measure will help with the LY week. 
LY week =
VAR LY =MAX ( 'Table'[Year] ) - 1
VAR Selectedweek = MAX ( 'Table'[Week Number] )
RETURN
CALCULATE (
        WEEKNUM(MAX ( 'Table'[Date] )),
        'Table'[Year] = LY, 'Table'[Week Number] = Selectedweek
    )
 
shivamdubey_0-1737694116430.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.