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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ale_BI
Helper I
Helper I

Ordering table not by alphabetical sort, or index

ale_BI_0-1669714913414.png

 

I have this table and I want to order it so that the order is Men, Women, Other, Total. How can I do that with Power Query? Also, when I change the order in DAX, and do a sort column on [Gender] by [Cod. Gender], it removes the Total from the graphs. 

Instead of looking like this:

ale_BI_1-1669715047166.png

 

It looks like this when I do the sort by: 

 

ale_BI_2-1669715082595.png

 

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @ale_BI ,

 

To get a custom sort order, you need to define it in a new column in your table.

For your scenario, you would add another column like this:

 

// In Power Query M
if [Cod. Gender] = "M" then 1
else if [Cod. Gender] = "F" then 2
else if [Cod. Gender] = "O" then 3
else 99

// OR

// In DAX
SWITCH(
  [Cod. Gender],
  "M", 1,
  "F", 2,
  "O", 3,
  99
)

 

 

Once you have your new column, go the Data View 

BA_Pete_0-1669730668173.png

 

Select your [Gender] column, then go to the Column Tools tab > Sort by Column

BA_Pete_1-1669730765325.png

 

Select your new sort key column from the list an the text values will now be sorted in order of your sort column instead.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

1 REPLY 1
BA_Pete
Super User
Super User

Hi @ale_BI ,

 

To get a custom sort order, you need to define it in a new column in your table.

For your scenario, you would add another column like this:

 

// In Power Query M
if [Cod. Gender] = "M" then 1
else if [Cod. Gender] = "F" then 2
else if [Cod. Gender] = "O" then 3
else 99

// OR

// In DAX
SWITCH(
  [Cod. Gender],
  "M", 1,
  "F", 2,
  "O", 3,
  99
)

 

 

Once you have your new column, go the Data View 

BA_Pete_0-1669730668173.png

 

Select your [Gender] column, then go to the Column Tools tab > Sort by Column

BA_Pete_1-1669730765325.png

 

Select your new sort key column from the list an the text values will now be sorted in order of your sort column instead.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors