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!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi everyone,
I’m working on a Power BI project aimed at identifying the number of prescriptions for products on the market. The prescription information (i.e., the number of prescriptions made) is stored in the Prescription Product table, which also contains the time period the data refers to.
I’m also using a Calendar table, linked to the Prescription Product table, to manage time-based filters used in the dashboard.
I’ve already created a measure (which I’ll paste later) that allows me to identify, for the latest MAT available (i.e., the sum of the last 4 quarters), the Top 5 products of a selected market (filtered by slicer).
Additionally, I need to include products that are not in the Top 5 but belong to one of the two “special” companies I’ve defined.
All other products in the selected market, which are neither in the Top 5 nor from the special companies, should be grouped under a single category called “Other.”
This measure is already working (its name is Top5 + Others + Special Product Range Quarter (Fixed Last 4Q)).
However, I’m struggling with one last thing:
I need to sort this measure in a matrix visualization according to the following logic:
First, show the Top 5 products (ranked from 1 to 5 based on the latest MAT value — the highest value should be rank 1);
Then show the “Other” category (rank = 6);
Finally, if present, show the special company products (rank > 6).
The ranking should be calculated only for the latest MAT available (the sum of the last 4 quarters) and should only appear for quarters where data actually exists, meaning it should not appear for quarters beyond the latest available date.
Could anyone kindly help me figure out how to handle this custom sorting logic?
Thanks a lot in advance! 🙏
Hi @Sarah_T ,
Are things clear now, or are you still facing any issues? Please let us know if you need any additional information, happy to help.
Hi, No, unfortunately I haven’t been able to sort out my problem yet.
Hi @Sarah_T ,
Could you let us know if your issue has been resolved or if you are still experiencing difficulties? Your feedback is valuable to the community and can help others facing similar problems.
Hi @Sarah_T ,
Thank you for sharing the screenshot and addiotnal details. The matrix is currently re ranking products for each quarter, but the order you’re expecting is based on the latest 4 quarters, as shown in your MAT view. To get the right order, you’ll need to calculate the ranking once using the last 4 quarter period and use that as the sort key in the matrix. You can then hide the rank field so it doesn’t appear in the visual.
Power BI doesn’t automatically keep this custom sort order, so you’ll need a rank field to maintain it. With the rank applied, the Top 5 and Other grouping will stay in the same order across all historical quarters, just like in the MAT matrix on the right.
Thanks for staying engaged and providing the extra context.
You should have a separate table with all the descriptions and the "Other" row, if the order is not dynamic but only based on the last available date you can add it to that table and use it to order the descriptions.
Otherwise, add a measure for the rank (=order) to the matrix and order by that, then hide it by resizing the column.
I already have a table where, for each identified market, I have all the corresponding descriptions, with the addition of the "Other" row.
However, I can’t add a rank to this table because, with the next data update, there might be products with significantly higher values, which would therefore change the selection of the top 5 products.
I tried creating a rank measure to order these Top 5 + Other + Special (always based on the sum of the last 4 quarters), but the sorting doesn’t come out correctly when I want to display it in a matrix with the entire history of quarters.
Here’s the formula I identified for the rank:
This formula calculates the rank for the MAT, for a matrix where only YTD and MAT are displayed.
What I need, however, is a rank formula that calculates the highest values based on the sum of the last 4 quarters, but to be displayed in a matrix that contains the full history of quarters.
Does anyone have any suggestions?
I can't see in your formula where you are filtering for "the last 4 quarters", you should add the filter appropriately.
It would help if you provided a sample of your report, especially if you want to needlessly complicate the DAX.
Unfortunately, I can’t provide an example of my report, but I can share the formula where I calculate the quarterly data for the top 5 products, based on the sum of the last four quarters.
I’m asking for help with the sorting not because I want to needlessly complicate the DAX formula, but because it’s a request coming from other people.
Hi @Sarah_T ,
As suggested by @Jai-Rathinavel , please prepare a small Power BI (.pbix) file or share some sample data along with the expected output. This will help us better understand the scenario and provide a more accurate solution.
Thanks @Jai-Rathinavel , for your helpful suggestion.
Best regards,
Yugandhar
Hi @Sarah_T It would be great if you could provide us a pbix file with sample / dummy data. You can upload the file to a dropbox and share the link with us by replying to this thread.
Thanks,
Jai
Proud to be a Super User! | |
Good morning everyone, unfortunately I cannot prepare a PBIX version as an example, but I am including a screenshot of the scenario I am referring to. Specifically, the matrix on the right, with the YTD and MAT metrics, shows the correct sorting I am requesting (sorting by MAT in descending order).
My additional request, which I am currently unable to implement, is to identify 5 fixed products plus all the others grouped together under the category "Other" with their respective sum (fixed based on the sum of the last 4 available quarters). For these 5 top fixed products plus the "Other" category, I need to see the data by quarter for the entire available history.
In this first matrix by quarter, these products must follow the same sorting order as in the matrix on the right. That is, in the example provided, the sorting for the matrix on the left must necessarily be:
HyaloGyn
Ozogin Hydra
Ainara
Santes
Meclon Idra
Other
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 |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 6 | |
| 5 |
| User | Count |
|---|---|
| 24 | |
| 21 | |
| 18 | |
| 14 | |
| 14 |