Forum Discussion
DAX Ranking Issue
- 10 months ago
Hi Taha_M
To better reproduce your issue, could you share a small sample of your data with the expected rank result?(not as a screenshot).Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community
Hi KNP. Firstly, thankyou for replying. This was my first post so sure your advice taken for the future!
I have tried your code and yes it gives correct ranking.
Similarly, if I remove the ProductID column from the matrix (since this column isn't passed to ALLSELECTED in my [Product Rank wrong] measure), I see that my measure gives correct ranking.
From this, I have come to the conclusion that if I include ProductID column in the matrix, during the evaulation of the measure for each row of the matrix it is filtering the Source Table to only 1 product (in the data model each product name has a unique product id and category id, I have attached the picture of data in the model beneath the text - it is a small practise dataset). Hence, since the ranking is performed for only a single product visible in the Source Table, it gets ranked 1.
This however contradicts what the maestros at SQLBI has to say about the behavior of ALLSELECTED(<columnName>) when used as table argument: The reference article is: link
"ALLSELECTED returns the values of a column as filtered by the last shadow filter context. The reader might have noticed that there is no active iteration when we call ALLSELECTED. Thus, there are no shadow filter contexts to activate. As a result, all the product names are returned because neither Color nor Brand filter the Product[Product] column – although it is cross-filtered............ALLSELECTED works on a column and checks whether that column is filtered by a shadow filter context, ignoring any cross-filter."
They say that the column passed to ALLSELECTED should not be cross-filtered by other columns of that same table since ALLSELECTED does not take into account the filter context. What seems to happen in our case violates this i.e. ProductID column is indeed cross-filtering CategoryID and ProductName columns and hence incorrectly narrowing down Source Table to single product each time the measure is evaluated within the matrix.
I would like to hear your thoughts if this is what you were speculating the issue to be aswell, and what do you think of my take at this SQLBI article.
Hi Taha_M
To better reproduce your issue, could you share a small sample of your data with the expected rank result?(not as a screenshot).Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community
- v-aatheeque10 months ago
Community Support
Hi Taha_M
To better reproduce and troubleshoot your scenario, we kindly request a small sample dataset/file. Please share it at your convenience, as this will help us provide a more accurate and tailored solution.