Showing results for 
Search instead for 
Did you mean: 
Post Prodigy
Post Prodigy

Sorting year weeks in Power BI



I would like to ask how to properly sort year week because in visual it seems unsorted:

Here is the view of it



Is possible to fix it?

Super User
Super User

Hi @Analitika ,


Due to the "-" in the middle of the Year-Week number, that value is stored as text. This is the reason the sorting is not working for you.


In order to sort it correctly, you can replace the Year-Week formula you are currently using with the following:


Year-Week = 
    VAR __Year = Year( [Date] )
    VAR __WeekNum = WEEKNUM( [Date] )

    IF( __WeekNum < 10, CONCATENATE( __Year, "-0" & __WeekNum ), CONCATENATE( __Year, "-" & __WeekNum ))


The difference is the "0" before any single-digit week numbers. This allows the sorting to work correctly.

Did I answer your question? Mark my post as a solution!
My LinkedIn
Solution Sage
Solution Sage


Changed data type as Date and format as below



I am getting this 



Hi @Analitika ,

Please create a new column on your date table like below :

YearWeekIndex = dim_date[Year] * 100 +dim_date[Week of Year]
Then select your YearWeek column, go to sort by column and click on 'YearWeekIndex'. Your yearweek field will now be sorted using this column.


Kind regards,


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊

Helpful resources

September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show Episode 10 Recap

The Power BI Community Show

Watch the playback when Amit Chandak, a Power BI Super User, demos how to use Field Parameters to make reports more dynamic.

Power BI Dev Camp Session 26

New Date - Check it Out!

Mark your calendars and join us on Thursday, October 6 at 11a PDT for a great session with Ted Pattison!

Health and Life Sciences Power BI User Group

Health and Life Sciences Power BI User Group

Power BI specialists at Microsoft have created a community user group where customers in the provider, payor, pharma, health solutions, and life science industries can collaborate.

Top Solution Authors