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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pborah
Continued Contributor
Continued Contributor

Alternative to WEEKNUM() for setting beginning and end of week?

So I have three measures for which the DAX code is - 

 

 

Count Last Week = CALCULATE(COUNT('Reports WeeklyReporting'[evt_rin]),'CALENDAR'[Week Number]=WEEKNUM(TODAY(),2)-1)

Count 2 Weeks Ago = CALCULATE(COUNT('Reports WeeklyReporting'[evt_rin]),'CALENDAR'[Week Number]=WEEKNUM(TODAY(),2)-2)

Count last 8 weeks = CALCULATE(COUNT('Reports WeeklyReporting'[evt_rin]),FILTER('CALENDAR',WEEKNUM('CALENDAR'[Date],2)>=WEEKNUM(TODAY(),2)-9 && WEEKNUM('CALENDAR'[Date],2)<=WEEKNUM(TODAY(),2)-1 && YEAR('CALENDAR'[Date])=YEAR(TODAY())))

 

 

In addition to that, I set a relative date filter to "This Year" so that the results are reflecting metrics relevant to this year only.

 

However these metrics break at the beginning of each year for upto the next 8 weeks. This is because  on the week of Jan 1, there is no "Last Week", or last two weeks or last 8 because of the relative date filter set to current year. Any ideas on how to get around this? I only discovered this early in january of 2022. While "Count Last Week" and "Count 2 Weeks Ago" have resolved on their own since enough time has lapsed, "Count Last Weeks" is still off because it hasn't been 8 weeks into 2022 yet.

 

For context, the relative date filter is necessary because we have data going back to 2017. So without the relative date filter those WEEKNUM results would include data for all prior years with the same weeknum. A week is defined as from 00:00 Monday to 23:59 Sunday. Unfortunately I cannot share the data. Thanks.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@pborah Check out Sequential: Sequential - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
pborah
Continued Contributor
Continued Contributor

@v-rzhou-msft Why did you accept it as a solution when I'm still testing it out? I posted this question, not you.

Greg_Deckler
Super User
Super User

@pborah Check out Sequential: Sequential - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
pborah
Continued Contributor
Continued Contributor

Thanks @Greg_Deckler ! So I'm using the column version for those unique week numbers/sequentials. However the counts are now incorrect. The DAX code I used for "Count Last Week" in my original question above give me the correct numbers but when I use unique week numbers based on sequentials, it is slightly off. 

Count Last WkTest = 
VAR Max_Week= MAX('CALENDAR'[Unique WeekNum])
VAR CaseCount = CALCULATE(COUNT('Reports WeeklyReporting'[evt_rin]),'CALENDAR'[Unique WeekNum]= Max_Week-1)
RETURN CaseCount

pborah_0-1647875526737.png

I've tried checking my data and verified the correct count numbers using the original formula from my team members. Am I doing something wrong using the sequentials? Thank you.

 

 

@pborah Make sure you are using the right 2nd parameter for WEEKNUM in your Sequential calculation?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
pborah
Continued Contributor
Continued Contributor

@Greg_Deckler that worked. I just had the relationship between the calendar table and my fact table set to bidirectional which was causing the error. I changed that and everything works fine. Thanks!

pborah
Continued Contributor
Continued Contributor

@Greg_Deckler I think I did that right. This is my calendar table. Report requirements indicate week start to be on a Monday.

pborah_0-1647883547135.png

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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