Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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:
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
Solved! Go to Solution.
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
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
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
Thank you, I spent a frustrating amount of time trying to figure out if a table from a query could be merged with a table from a DAX calculation. I don't understand why Google couldn't tell me that. Oh that's right, the ensh*ttification of the internet. Anyway, I tried all the other online things - creating a relationship, etc and it won't sort, but that wasn't the question I asked anyway. Thanks for helping. I guess I can mark your answer as correct? I'm not sure that's right, but I'm happy to if it helps you out with points.
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.
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.
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?
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
112 | |
105 | |
97 | |
38 | |
30 |