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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
cheid1977
Advocate I
Advocate I

Sort Order Question

I created a formula to put shipping weights into weight ranges (0 - 5, 10 - 20, etc.). The problem I am having is that the weight ranges are not in the correct order from smallest to largest.  For example after 10 - 20 it jumps to 100 - 150, then to 1000 - 2000. Is there anyway to put these in order?

3 REPLIES 3
cheid1977
Advocate I
Advocate I

I created a second column. When I went to sort per your instructions I got error message "This column can't be sorted by a column that is alreadsy sorted, directly or indirectly, by this column".  Is this anyway related to using DirectQuery?

AlbertoFerrari
Most Valuable Professional
Most Valuable Professional

Likely, you based the second column on the first one. Something like: "IF RANGE IS 10-20 THEN 1 ELSE ...".

This makes the sorter column (your second one) dependant on the sorted one (the calculated range). In such a case, you cannot use the sort-by-column feature.

You need to remove the dependency in one of two ways:

- you repeat the full logic in the sorter, so to avoid the dependency

- you reverse the dependency by first creating the sorter, and then assign a description to the sorted column based on the sorter

Either ways, the dependency is removed or switched in a direction that DAX likes more.

 

What I prefer is to first compute the sorter, then the sorted. Something like this:

 

Sorter = 
SWITCH (
    TRUE (),
    YourTable[Weight] < 100, 1,
    YourTable[Weight] < 1000, 2,
    YourTable[Weight] < 10000, 3
)

Sorted =
SWITCH ( 
    YourTable[Sorter],
    1, "LESS THAN 100",
    2, "100-1000",
    3, "1000-10000".
    "VERY HEAVY"
)
 

In this scenario, Sorted can now be sorted by Sorter.

 


Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI
TomMartens
Super User
Super User

Hey,

 

the problem you face is due to the fact, that the string columns are ordered alphabetically by default. To solve this issue you have to create a second column of data type whole number (this column can be hidden from report view). Assign a proper value to this column.

In a product table your columns than may look like this

Product | Weight Range | SortOrder

Product A | 10 - 20 | 1

Product B | > 100 | 3

Product C | 21 - 100 | 2

Product D | 10 - 20 | 1

 

Please be aware, that the same value for the SortOrder column has to be assigned for the same value of the Weight Range column.

 

In the model pane

  • switch to the Modeling menu
  • mark the column weight range and 
  • select the newly created colum from the Sort By Column submenu

Sort Column by.png

 

Hope this helps

Regards

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors