Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
When I use RANKX, it seems to cause a cartesian join across a relationship.
Example:
FACTtable
ColourId | Value |
1 | 6 |
2 | 2 |
3 | 7 |
4 | 2 |
5 | 1 |
5 | 4 |
DIMtable
ColourID | Colour |
1 | Red |
2 | White |
3 | Blue |
4 | Orange |
5 | Purple |
Create a relationship between these on ColourID
Now create a RANKX measure:
The ranking causes a strange cartesian join that we can see when we add the colour IDs from each respective table:
Now we can fix this by changing the RANK function to be:
My question is. Am I doing something wrong? It took a lot of research and digging to find the solution to this and it doesn't really feel intuitive. When I look at other people's example online, they don't seem to have this issue and there aren't that many posts about this issue online. I'd have thought the forums would be full of this type of issue.
Am I doing my RANKX wrong or does Power BI just expect us to use HASONEVALUE every time we use RANKX?
The function works fine on a single table if you merge your DIMs into your FACT but obviously this goes against all guidance, yet there is no explicit guidance on how to use RANKX properly in a Dimensional model.
Solved! Go to Solution.
Such a seemingly simple issue involves many intricacies under the hood. Even a seasoned DAX user might be incapable to wrap his head around it.
all rows can be made dissapear this way,
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Hi , @tbennett93
According to your description, you want to show the table , like this:
But when you put the field you need on the visual , it seems to occur the "crossjoin".
The dax you use for this need is right:
rankcol = RANKX(all('FACTtable'),CALCULATE(SUM('FACTtable'[Value])))
But for the ALL() function used , it clear the filter in fact table. Internal,it also clear the filter of the Dim table, so when you put the 'DImTable'[Colour] field on the visual , it occur the "Crossjoin"!
If you just put the measure in the fact table , it works perfectly:
So for this question, you can create another measure to show the color name :
Color Name = var _colorId = MAX('FACTtable'[ColourId])
var _t = FILTER('DIMtable','DIMtable'[ColourID] = _colorId)
return
MAXX(_t,[Colour])
Then in the end we can meet your need:
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Such a seemingly simple issue involves many intricacies under the hood. Even a seasoned DAX user might be incapable to wrap his head around it.
all rows can be made dissapear this way,
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
User | Count |
---|---|
47 | |
27 | |
23 | |
18 | |
15 |
User | Count |
---|---|
55 | |
34 | |
18 | |
17 | |
15 |