Forum Discussion
X-Axis Not Sorting in Categorical Order
My x-axis in the chart is going in a random order. I imagine this is due to it being stored as text and because of the hyphen, is there a way around this issue, so that it does 17-2017, 18-2018, 19-2019, 20-2020, 20-2021, 21-2021?
Thanks!
Anonymous
Refer to this document..
https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column
You have to create an index column and use that as SORT BY column to your category.
There are tons of post in the forum for SORT BY..
If it helps mark it as a solution
Kudos are nice too
3 Replies
- VasTg
Memorable Member
Anonymous
Refer to this document..
https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column
You have to create an index column and use that as SORT BY column to your category.
There are tons of post in the forum for SORT BY..
If it helps mark it as a solution
Kudos are nice too - jmalone
Resolver III
You can add a new column to give you the desired sort order. This new column will be a number, not a text.
Creating the sort column in the Query Editor, you can use this formula:
( Number.From( Text.Start([Text Column], 2) ) * 10000 ) + Number.From( Text.End([Text Column],4) )Where [Text Column] is the name of your existing column.
After loading the data to your model, sort your original column by this new, numerical column. There is a button in the ribbon called "sort by column"
- v-lili6-msft
Community Support
hi Anonymous
For your case, you could just add Year-weeknum column that format is 2017-17,2018-18,2019-19,2020-20,2021-20, 2021-21.
Then selected weeknum-year column(17-2017, 18-2018, 19-2019, 20-2020, 20-2021, 21-2021), set sort by column with Year-weeknum column.
https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column
https://radacad.com/sort-by-column-in-power-bi
Regards,
Lin