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
Rose1976
Regular Visitor

How do I create a meaure in order to sort categories in an order I want to dictate?

Hi, I need to sort my categories into a specic order, I have created a new table giving each category a unique number and connected this table to the categories in relationships.  However, I believe I need to create a measure in order to make the sort work.  Not sure what the code should be, can anyone help me please?

2 ACCEPTED SOLUTIONS

Hi there.

 

Happy to help. Some clarifying questions. Are you trying to sort the category order in a slicer/filter, or in a table? If you're trying to create a "sort column" then you don't need a seperate table, you can create a sort column on whatever table the categories are in using the SWITCH function.


Example:

 

=
SWITCH (
    TRUE (),
    Table[Category] = "Value A", 1,
    Table[Category] = "Value B", 2,
    BLANK ()
)

 

If you include a TRUE() in the SWITCH expression, it checks each statement, and if true returns the value you give it. I'm giving it a numerical value since DAX understands how to sort those. Then you use the "Sort by Column" function in the table view and sort your category column by this new (1,2,3) sort colum. Let me know if this helps!

 

Reid Havens - Owner

Havens Consulting Inc.

View solution in original post

v-caliao-msft
Employee
Employee

@Rose1976,

 

I have created a new table giving each category a unique number and connected this table to the categories in relationships.

When sorting a column, you can only use the columns inside the same table. So you need to create a calculated column in your orginal table. You can use Reid_Havens's expression to create the order column.

Capture.PNG

 

Regards,

Charlie Liao

 

View solution in original post

2 REPLIES 2
v-caliao-msft
Employee
Employee

@Rose1976,

 

I have created a new table giving each category a unique number and connected this table to the categories in relationships.

When sorting a column, you can only use the columns inside the same table. So you need to create a calculated column in your orginal table. You can use Reid_Havens's expression to create the order column.

Capture.PNG

 

Regards,

Charlie Liao

 

Hi there.

 

Happy to help. Some clarifying questions. Are you trying to sort the category order in a slicer/filter, or in a table? If you're trying to create a "sort column" then you don't need a seperate table, you can create a sort column on whatever table the categories are in using the SWITCH function.


Example:

 

=
SWITCH (
    TRUE (),
    Table[Category] = "Value A", 1,
    Table[Category] = "Value B", 2,
    BLANK ()
)

 

If you include a TRUE() in the SWITCH expression, it checks each statement, and if true returns the value you give it. I'm giving it a numerical value since DAX understands how to sort those. Then you use the "Sort by Column" function in the table view and sort your category column by this new (1,2,3) sort colum. Let me know if this helps!

 

Reid Havens - Owner

Havens Consulting Inc.

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