cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BenEaton Frequent Visitor
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

Accepted Solutions
Community Support Team
Community Support Team

Re: "Sort by column" - from a related table

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.
6 REPLIES 6
Super User
Super User

Re: "Sort by column" - from a related table

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.


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!


Highlighted
BenEaton Frequent Visitor
Frequent Visitor

Re: "Sort by column" - from a related table

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

 

Super User
Super User

Re: "Sort by column" - from a related table

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


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!


Community Support Team
Community Support Team

Re: "Sort by column" - from a related table

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.
BenEaton Frequent Visitor
Frequent Visitor

Re: "Sort by column" - from a related table

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.

 

 

benny_sal Visitor
Visitor

Re: "Sort by column" - from a related table

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