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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
BenEaton
Frequent Visitor

"Sort by column" - from a related table

Hi all,

 

I'm looking to sort a column, but by an order defined in another table.  Specifically, I have military ranks that display alphabetically:

 

Capt

Maj

Sgt

SSgt etc...

 

...But naturally, wish to display them by a defined order which I have placed into a "Reference" table:

 

Reference:

Rank Reference.png

 

 

 

 

 

 

 

 

 

 

Even though there is a relationship between "Rank" in the source table and "Rank" in the reference data, I can't sort the data by the "RankOrder" column.  I can only sort by columns that already exist in the source data.  I do not want to edit the source data directly as I work from lots of different spreadsheets that all share this "Rank" column, so need a method of sorting.

 

I tried a calculated column of this format:

RankOrder1 = LOOKUPVALUE('Reference'[RankOrder],'Reference'[Rank],'Source Table'[Rank]) , which adds the correct number next to each value, but when I try sorting by this it displays the error:

 

"Sort by another column error:  This column can't be sorted by a column that is already sorted, directly or indirectly, by this column."

 

 

Any help would be greatly appreciated.

 

Ben

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @BenEaton,

 

Now that you have created a one to many relationship between  reference table and source table, then you can use this formula to add calculated column: RankOrder1 = RELATED(Reference[RankOrder]). Then, click the "sort by column" button, select RankOrder1. In the visualisations, slicers etc, you will have the correct sorting.

 

If you have any question, please feel free to ask.

 

Best regards,
Yuliana Gu

 

 

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
benny_sal
Regular Visitor

just try PBI after company switch from Tableau (too expensive for them), I just find it more easy way in PBI Nov 2017 version like this:

1. Sort "Rank" in Reference table by "RankOrder", and connected to main table with correct relationship.

2. just use "Rank" from Reference table (not Rank in main table) in your chart/table, it will sorted by RankOrder, it's work and I'm already try it.

Sorry for any misstype, english is not my native, over all PBI is very poor compare to Tableau, but we get what we pay

Benny Sal

v-yulgu-msft
Employee
Employee

Hi @BenEaton,

 

Now that you have created a one to many relationship between  reference table and source table, then you can use this formula to add calculated column: RankOrder1 = RELATED(Reference[RankOrder]). Then, click the "sort by column" button, select RankOrder1. In the visualisations, slicers etc, you will have the correct sorting.

 

If you have any question, please feel free to ask.

 

Best regards,
Yuliana Gu

 

 

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Greg_Deckler and @v-yulgu-msft,

 

Didn't have time to check to post sample data, by the time it was solved!  the RELATED function worked perfectly, many thanks @v-yulgu-msft.

 

 

Greg_Deckler
Super User
Super User

In your visualization, use the Rank column from your reference table and set the Sort By to your RankOrder column. If there is a relationship between your tables based on Rank, then it shouldn't matter that you use the column from your reference table versus your fact table and then you will have the correct sorting.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

I feel like I did this in a prior file and it worked and it doesn't work in my current file. Do the reference tables have to be pre-sorted?

thanks!

Hi @Greg_Deckler,

 

Thanks for the tip, but just tried that to no effect, the visualisations, slicers etc all remain alphabetical!  It's one to many relationship from reference to source data (if that matters).

 

Can you post some sample data or your PBIX file so that I can take a look or recreate your issue?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.