Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I'm using a slicer to select a "Sort type" for a visualization I have. Depending on what value is selected, I am planning to use that as the sort option for a RANKX function I have. For some reason when I use a variable to get the selected value (since I cannot see the table from inside the RANKX inner part) I get an error that says that it expects the ORDER argument to be 0/FALSE/DESC etc. The funny thing is that if I pass in a hardcoded value to my variable it works fine. Is there something I'm missing here in order to get it to work? Here is an example of the code I have:
Solved! Go to Solution.
Another option might be to flip the sign of the measure depending on Top/Bottom.
VariableRank =
VAR Sgn = IF ( SELECTEDVALUE ( 'Top or Bottom'[Option] ) = "Top", 1, -1 )
RETURN
RANKX ( ALLSELECTED ( MyTable[pageTitle] ), Sgn * [Total PageViews] )
Another option might be to flip the sign of the measure depending on Top/Bottom.
VariableRank =
VAR Sgn = IF ( SELECTEDVALUE ( 'Top or Bottom'[Option] ) = "Top", 1, -1 )
RETURN
RANKX ( ALLSELECTED ( MyTable[pageTitle] ), Sgn * [Total PageViews] )
Sweet! I liked this solution as it is simple enough to understand and for my particular scenario. Thanks a lot to everyone else for their soultions!
Hello @ebecerra ,
We can achieve it by a little different method. By adding two rank functions in an if-else clause. The issue is RANKX function couldn't accept variables in the ORDER attribute.
You can find the solution and measure formula below :
Thanks,
Neel
@ebecerra , better create two rank Var or measure with Asc and desc rank and use that
Example - All measures
Rank1 = Rankx(Allselected(Sales), [Sales],,asc,dense)
Rank2 = Rankx(Allselected(Sales), [Sales],,desc,dense)
if(selectedvalues(Table[Sort Order]) =1, [Rank1], [Rank2] )
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
8 | |
7 |