Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
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:
Any help would be greatly appreciated.
Many thanks in advance
Image 1
image 2
Solved! Go to Solution.
@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
⭕ 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
@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
⭕ 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
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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
144 | |
75 | |
63 | |
51 | |
48 |
User | Count |
---|---|
204 | |
86 | |
62 | |
59 | |
56 |