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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Analitika
Post Prodigy
Post Prodigy

Sorting year weeks in Power BI

Hello,

 

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

Here is the view of it

 

Analitika_0-1653394254537.png

Is possible to fix it?

4 REPLIES 4
Adescrit
Impactful Individual
Impactful Individual

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] )

RETURN
    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
ddpl
Solution Sage
Solution Sage

Hi

Changed data type as Date and format as below

ddpl_0-1653394542121.png

 

I am getting this 

Analitika_0-1653395750536.png

 

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.

rohit_singh_0-1653396368691.png

Kind regards,

Rohit


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

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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