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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sarjensystems1
Helper III
Helper III

Dynamic Top N with hirarchy in matrix Visual

doubt.PNG

Hii

i have a requirement to display dynamic Top N category based on country and i am using Matrix visual

i am using this DAX function

TopN Sales=
VAR SelectedTop = SELECTEDVALUE('TopN'[TopN])
RETURN
SWITCH(TRUE(),
SelectedTop = 0, [sales],
RANKX (
ALL( Query1[Category]),
[sales]
)
<= SelectedTop,
[sales]
)
this is working fine...but when i drag subcategory to the matrix it is displaying wrong values...(filtering both category and subcategory)
my requirement is to display top N Category Values with out filtering the subcategory...
How to do this???
Thanks....
1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @sarjensystems1 ,

 

I have changed your measure and I guess this time it will satisfy your need:

 

 

TopN Sales = 
VAR SelectedTop = SELECTEDVALUE('TopN'[TopN])
RETURN
SWITCH(TRUE(),
SelectedTop = 0, [sales],
RANKX ( 
ALL('Table'),
[sales]
)
<= SelectedTop,
[sales]
)

 

And you will see:

 

Annotation 2020-02-12 112528.png

 

For the related .pbix file,pls click here.

 


 
Best Regards,
Kelly

View solution in original post

4 REPLIES 4
v-kelly-msft
Community Support
Community Support

Hi @sarjensystems1 ,

 

I have changed your measure and I guess this time it will satisfy your need:

 

 

TopN Sales = 
VAR SelectedTop = SELECTEDVALUE('TopN'[TopN])
RETURN
SWITCH(TRUE(),
SelectedTop = 0, [sales],
RANKX ( 
ALL('Table'),
[sales]
)
<= SelectedTop,
[sales]
)

 

And you will see:

 

Annotation 2020-02-12 112528.png

 

For the related .pbix file,pls click here.

 


 
Best Regards,
Kelly

v-kelly-msft
Community Support
Community Support

Hi @sarjensystems1

 

I'm not sure whether [sales] is a column or measure,but I tried to use your sample data and create a measure names [sales],when I select subcategory,it appears right, as you can see below:

 

171.png

For the related .pbix file,pls click here.

 

Best Regards,

Kelly

Ashish_Mathur
Super User
Super User

Hi,

Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

I did not test it but

You might have to try ALLEXCEPT( Query1[Category]) in place of ALL( Query1[Category]).

Refer

https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.