Forum Discussion
Am I Using RANKX Incorrectly? It causes a cartesian join across relationships.
- 3 years ago
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.
- It's NOT rankx() that causes the cartisian product but it's the fact the cartisian product already exists there and those "unreasonable" rows are "accidentally" made visible by your measure.
Here's a simple way to prove its existence,
all rows can be made dissapear this way,
- When you drag columns into a viz functions, they function independently as separate filters; a measure evaluates under the comprehensive effects of all these filters. As long as a measure evaluates any value other than BLANK(), the correspondent row shows.
- A reasonable measure can be authored this way
- Rankx() is one of the most frequently used and also trickiest functions in DAX. Once you manage to master it, DAX is almost under full control.
- It's NOT rankx() that causes the cartisian product but it's the fact the cartisian product already exists there and those "unreasonable" rows are "accidentally" made visible by your measure.
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