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
Dyrham
New Member

How to get the right weeknumber?

When I transform my date table to week number of the year, I get it wrong. The week number is +1 when I do this. How do I handle this?

2 ACCEPTED SOLUTIONS
sudhav
Helper V
Helper V

sudhav_0-1673774914776.png

take new column and write a DAX 

View solution in original post

Hi Tom.

Thank you for your quick answer, I will try it later on. I send you some Kudos even though I haven't tested it yet.

Best Regards 

Dyrham from Uddevalla Sweden

View solution in original post

3 REPLIES 3
TomMartens
Super User
Super User

Hey @Dyrham ,

I have to admit that it's difficult to understand what you mean by you get "wrong week number," this is because more than one valid concept for a week number exists.

 

As I'm living in Germany, most often, people ask for the ISO week number. This can be achieved by the following DAX code, a column is added to an calendar table:

calendar = 
ADDCOLUMNS(
    CALENDAR( DATE( 2020 , 1 , 1 ) , DATE( 2023 , 12 , 31) )
    , "ISO WEEK" , WEEKNUM( [Date] , 21 )
)

The next picture shows the result:

TomMartens_0-1673774580213.png

There is a little challenge with the ISO week number, as a week number sometimes spans multiple years. For this reason, I tend to create a column that contains the year and the ISO week number, a combination of the year of the starting day of a week and the ISO number. The next DAX is exactly doing this. Next to the week number, it contains the start and end day of the week. Both dates are based on the "concept" the start day of the week is a Monday.

calendar = 
ADDCOLUMNS(
    CALENDAR( DATE( 2020 , 1 , 1 ) , DATE( 2023 , 12 , 31) )
    , "SoWDate" , [Date]  - WEEKDAY([Date],2) + 1 
    , "EoWDate" ,  [Date] + 7 - WEEKDAY([DATE],2)
    , "ISO WEEK" , WEEKNUM( [Date] , 21 )
    , "YYYY ISO WEEK" , YEAR( [Date]  - WEEKDAY([Date],2) + 1 ) & " " & WEEKNUM( [Date] , 21 )
)

The final result:
image.png

Hopefully, this provides an idea of how to tackle your challenge.

 

Regards,

Tom 

 



  



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom.

Thank you for your quick answer, I will try it later on. I send you some Kudos even though I haven't tested it yet.

Best Regards 

Dyrham from Uddevalla Sweden

sudhav
Helper V
Helper V

sudhav_0-1673774914776.png

take new column and write a DAX 

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.