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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors