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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
zanottiluca
Helper II
Helper II

SAMEPERIOD LAST Year behaving different by month and week

hi expert, 

I may need your expertise as I have encounter an odd scenario. 
I am using SAMEPERIODLASTYEAR and by comparing month by month it is behaving perfectly (image below). 
The issue happens when I put the week, where the number does not make sense. 
Calendar is formatted as a Date table. 
Dax I am using is this one: 

Visits LY = CALCULATE([# of Cases], SAMEPERIODLASTYEAR('Calendar'[Dates]))


Any help would be greatly appreciated. 
Many thanks in advance

Image 1

by month ok.PNG
image 2

zanottiluca_0-1705250466056.png

 

2 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@zanottiluca 

Try this meaure, however, weeks are different from year to year sometimes:

Visits LY = 
VAR __PreYear = SELECTEDVALUE('Calendar'[Year]) - 1
VAR __PreWeekNum = SELECTEDVALUE('Calendar'[Week Number])
VAR __Result = 
CALCULATE(
    [# of Cases],
    'Calendar'[Year] = __PreYear,
    'Calendar'[Week Number] = __PreWeekNum
)
RETURN
    __Result




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

thanks @Fowmy  this has solved the issue and also (for future reader) I have been able to put in a drill through  line chart (upper level Month and lower level weeknumber) either measure by leveraging the below:
basically the %difference 2 use the above formula while the second uses the SAMEPERIODLASTYEAR  

Difference by time select = IF(ISINSCOPE('Calendar'[WeekNumber]),[% difference2],[% difference])

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@zanottiluca 

Try this meaure, however, weeks are different from year to year sometimes:

Visits LY = 
VAR __PreYear = SELECTEDVALUE('Calendar'[Year]) - 1
VAR __PreWeekNum = SELECTEDVALUE('Calendar'[Week Number])
VAR __Result = 
CALCULATE(
    [# of Cases],
    'Calendar'[Year] = __PreYear,
    'Calendar'[Week Number] = __PreWeekNum
)
RETURN
    __Result




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

thanks @Fowmy  this has solved the issue and also (for future reader) I have been able to put in a drill through  line chart (upper level Month and lower level weeknumber) either measure by leveraging the below:
basically the %difference 2 use the above formula while the second uses the SAMEPERIODLASTYEAR  

Difference by time select = IF(ISINSCOPE('Calendar'[WeekNumber]),[% difference2],[% difference])
gmsamborn
Super User
Super User

Hi @zanottiluca 

 

DAX Time Intelligence functions are meant to work with YEAR, QUARTER, MONTH, and DAY.  WEEK isn't handled.

 

The reason for this is Week 1 of 2023 doesn't necessarily correspond with Week 1 of 2022.

 

For example, (with weeks starting on Sunday) 2024/01/01  is a Sunday so it would be Week 1.  On the other hand, 2023/01/01 is a Saturday and Week 1 so 2023/01/02 is a Sunday and a new week (Week 2).

 

These inconsistencies exist for every year because 7 * 12 = 364, not 365.  Also, not all years start on a Sunday.  Some years are more obvious than others.

 

Whenever I am working with weeks, I use a date table I have that was written in 'M' - Power Query  (I didn't write it but I have used it regularly. )  It includes the following week-related columns:

Week of Year
Week of Month
Start of Week
End of Week
Yr-Week
Yr-Week number
Week Offset

 

This date table makes handling weeks easier but does not handle the inconsistencies noted above.

 

I hope this makes sense.

 

SPLY - M dimDate.pbix

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.