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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
rmcgrath
Advocate II
Advocate II

Need help sorting X-axis

Trying to sort my X-axis where my values are text.  I needed to show "Week-Day" and so I end up with values like "103-1", "98-2", etc.  The problem I'm having after clicking the three dot menu on the line chart and sorting by "Week-Day", "Ascending" is any of the 100 numbers come right after zero?  I assume because they start with 1?  How could I fix this so they are in the proper order?

 

rmcgrath_0-1749838761646.png

 

 

 

1 ACCEPTED SOLUTION
SamsonTruong
Solution Supplier
Solution Supplier

Hi @rmcgrath ,

One solution to this is creating a new calculated column for sorting. The DAX calculated column would be as follows:

WeekDaySortOrder = 
VAR WeekNum = VALUE(LEFT('YourTable'[WeekDay], FIND("-", 'YourTable'[WeekDay]) - 1))
VAR DayNum = VALUE(RIGHT('YourTable'[WeekDay], LEN('YourTable'[WeekDay]) - FIND("-", 'YourTable'[WeekDay])))
RETURN WeekNum * 10 + DayNum


This will make a new column that turns your values such as "103-1" to 1031 and "98-2" 982. From here, we will use this new column to sort your original WeekDay column.

In your table view tab, select your WeekDay column. In the top ribbon, click on the sort by column option and select the newly created column. This will sort your original column by the new column.

SamsonTruong_0-1749850116832.png

If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.

Thanks,

Samson

 

Connect with me on LinkedIn

Check out my Blog

Going to the European Microsoft Fabric Community Conference? Check out my Session

 

 

View solution in original post

3 REPLIES 3
SamsonTruong
Solution Supplier
Solution Supplier

Hi @rmcgrath ,

One solution to this is creating a new calculated column for sorting. The DAX calculated column would be as follows:

WeekDaySortOrder = 
VAR WeekNum = VALUE(LEFT('YourTable'[WeekDay], FIND("-", 'YourTable'[WeekDay]) - 1))
VAR DayNum = VALUE(RIGHT('YourTable'[WeekDay], LEN('YourTable'[WeekDay]) - FIND("-", 'YourTable'[WeekDay])))
RETURN WeekNum * 10 + DayNum


This will make a new column that turns your values such as "103-1" to 1031 and "98-2" 982. From here, we will use this new column to sort your original WeekDay column.

In your table view tab, select your WeekDay column. In the top ribbon, click on the sort by column option and select the newly created column. This will sort your original column by the new column.

SamsonTruong_0-1749850116832.png

If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.

Thanks,

Samson

 

Connect with me on LinkedIn

Check out my Blog

Going to the European Microsoft Fabric Community Conference? Check out my Session

 

 

I love the idea, but it throws an error:  

rmcgrath_0-1749861988845.png

 

Hi @rmcgrath ,

It appears you be might be trying to do this as a measure. The code provided will only work as a calculated column.

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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