Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

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.

MohamedHesham_2-1630943707222.png

 

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

MohamedHesham_4-1630944066490.png

 

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?)

MohamedHesham_7-1630944445319.png

 

 

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).

MohamedHesham_3-1630943830457.png

Data model

MohamedHesham_6-1630944352206.png

 

 

 

 

6 REPLIES 6
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

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.
Anonymous
Not applicable

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.

 

 

 

 

mahoneypat
Microsoft Employee
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!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Sadly, same results @mahoneypat 

MohamedHesham_0-1630958261685.png

 

MohamedHesham_1-1630958274316.png

 

amitchandak
Super User
Super User

@Anonymous , Try TOPN

example

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

 

TOPN: https://www.youtube.com/watch?v=QIVEFp-QiOk&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=42

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Sadly same results @amitchandak 

MohamedHesham_0-1630946842406.png

 

MohamedHesham_1-1630946867023.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.