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

View all the Fabric Data Days sessions on demand. View schedule

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
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.