Problem with RANKX

Hi every,
i have a number of agencies wich i want to rank according to the % of engagement.
i used this formula:


ISBLANK([% ENG de l’Agence]);


RANKX(ALL(‘Code Agence’[AGENCE]);[% ENG de l’Agence];;;Dense)


it works fine as long as i put this measure in the same table with agencies. but what i want is to show the ranking seperateley not in a table.

now when i want to use the agence as a slicer ( i have already two slicers (year and quarter of year)), the ranking become weird

number 120 is rank nuber 1 but the measure shown seperateley gives 2.

Any idea?!.



The problem here is one of evaluation context. DAX measures need to be evaluated against something. The most common way of doing this is in a table or matrix visual, like the one you created here, where AGENCE serves as the evaluation context for your RANKX measure:


When you separate measures from their evaluation context, that’s when things can start to go sideways. However, this doesn’t mean that you always need to show the evaluation context. One of the most powerful features in DAX is the ability to manipulate evaluation context through the use of virtual tables. Thus, you can include a virtual table variable(s) in your measure that provides the proper evaluation context, evaluate your measures and then return results to your visuals without ever showing the evaluation context.

@sam.mckay has a ton of great content on manipulating virtual tables. Here a good intro:

and then a big “deep dive”

I hope this is helpful. If you need additional assistance with this, please provide a copy of your PBIX file and I will be glad to work through a more specific solution with you.

  • Brian

P.S. Update: I just found the following , where: @sam.mckay demonstrates a RANKX scenario w/ a virtual table:

1 Like

Hi @EMNA, we’ve noticed that no response has been received from you since the 14th of April. We just want to check if you still need further help with this post? In case there won’t be any activity on it in the next few days, we’ll be tagging this post as Solved. If you have a follow question or concern related to this topic, please remove the Solution tag first by clicking the three dots beside Reply and then untick the checkbox. Thanks!