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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.