Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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!

 

3 Replies

  • jmalone's avatar
    jmalone
    Icon for Resolver III rankResolver 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"