cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## Filtering by RANKX

I am relatively new to DAX and I have been trying to use RANKX to filter the top 3 medalists as seen below.

This is the result, which is true (Neglecting the total)

But the moment I try to map the ID to name and gender (both are in another table, see below) it starts to acting in a unexpected way. For Example (is this top 3 for each gender?)

This is what I am trying to achieve (This was by using Top N in the Filter panel but I want to use DAX instead).

Data model

6 REPLIES 6
Community Support

Can you share some sample data so that we could check the formula?

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Frequent Visitor

Hi, @v-jayw-msft

This is just a personal project to gain hands on experience using Power BI, so feel free to view the whole file.

I created a report page called "TESTING TOP N" where you can check the formula and what I am trying to achieve.

Thank you in advance.

Microsoft Employee

You can try an expression like this one.

Top 3 Medal Count =
VAR top3 =
TOPN ( 3ALLSELECTED ( 'Medalists'[ID] ), [Total Medals Medalists], DESC )
VAR result =
CALCULATE ( [Total Medals Medalists], KEEPFILTERS ( top3 ) )
RETURN
result

Pat

Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

@mahoneypa HoosierBI on YouTube

Frequent Visitor

Sadly, same results @mahoneypat

Super User

@MohamedHesham , Try TOPN

example

calculate([total medal medlist],TOPN(3,allselected(Table[ID]),[total medal medlist],DESC), values(Table[ID]))

Frequent Visitor

Sadly same results @amitchandak