Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!View all the Fabric Data Days sessions on demand. View schedule
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:
It looks like this when I do the sort by:
Solved! Go to Solution.
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
Select your [Gender] column, then go to the Column Tools tab > Sort by Column
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
Proud to be a Datanaut!
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
Select your [Gender] column, then go to the Column Tools tab > Sort by Column
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
Proud to be a Datanaut!
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 11 | |
| 8 | |
| 6 | |
| 5 | |
| 3 |