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
Anonymous
Not applicable

DAX Weeknum

Hi

 

Here in year 2021 I notice several of my reports where I use a "Year Week" DAX function, the result gives the wrong week number.

Data from 4th of  january to 10th should show up as in week 1, but instead it shows up in week 2. Data from 11th of january to 17th of january shows up as week 3 but should be week 2.

 

I'm using this coloumn formula:

Year Week = YEAR([Date]) & "-" & if(WEEKNUM([Date],2)<10,CONCATENATE(0,weeknum([Date],2)),weeknum([Date],2))

 

And I have tried to subtract 1 from the weeknum, if the year is 2021, but that doesn't change the result:

Year Week = YEAR([Date]) & "-" & if(YEAR([Date]) = 2021,if(WEEKNUM([Date],2)<10,CONCATENATE(0,weeknum([Date],2)-1),weeknum([Date],2)-1),if(WEEKNUM([Date],2)<10,CONCATENATE(0,weeknum([Date],2)),weeknum([Date]+1,2)))
 
Could any one help me on this?
1 ACCEPTED SOLUTION
Payeras_BI
Super User
Super User

Hi @Anonymous ,

 

Payeras_BI_1-1611229124522.png

 

 

Regards,

 

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

View solution in original post

6 REPLIES 6
Payeras_BI
Super User
Super User

Hi @Anonymous ,

 

I am glad it helped.

 

In additon to get the first three days of 2021 in your Year Week calculated column like 2020-53 and not 2021-53 use the following code for the ISO Year:

 

Payeras_BI_1-1611237087054.png

 

Regards,

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain
Geradav
Responsive Resident
Responsive Resident

@Anonymous To obtain ISO Week Number you need to use 21 as the second argument as mentioned by @Payeras_BI 

Geradav_1-1611230562451.png

 

Payeras_BI
Super User
Super User

Hi @Anonymous ,

 

Payeras_BI_1-1611229124522.png

 

 

Regards,

 

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain
Anonymous
Not applicable

Edit: It did actually work! 😉

 

Thanks, it doesn't work for me.

amitchandak
Super User
Super User

@Anonymous , I think this same as issue reported here

https://community.powerbi.com/t5/Issues/DAX-WEEKNUM-gives-incorrect-values-since-jan-1st-2021/idi-p/1583824


In calendar add these columns

Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1

min week start of year = minx(filter('Date',year([Week Start date])=earlier(year(Week Start date]))),[Week Start date])

 

week No = quotient(datediff([min week start of year],[date],day),7)+1

 

 

Anonymous
Not applicable

Thanks, I will see if I can implement this in my report

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.