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

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

Reply
sim_kay7
Frequent Visitor

Display only certain rows of a matrix visual based on a column's rank with DAX

Hello,

I have a matrix visual showing costs and turnover for different products for 2020 and 2021.

I also created measure to get the rank of a product in terms of costs and turnover.

 

sim_kay7_0-1638884564566.png

I'm trying to find a way to display only those rows of products where costs in 2021 are within the top3 (without using the filter pane).

 

Can anybody give a hint how to do it?

 

Cheers

Simkay

1 ACCEPTED SOLUTION

@Jihwan_Kim I added an intermediate step to summarize the costs per product per year.

 

Now it works. Thanks for your help!

 

Here is the full solution:

sim_kay7_0-1638963672656.png

 

Cheers, Simkay

 

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

 

Picture1.png

 

_Costs: =
VAR yearselect = 2021
VAR newtable =
FILTER ( ALL ( Data ), Data[Year] = yearselect )
VAR topthreecost =
TOPN ( 3, newtable, Data[Costs], DESC )
VAR withoutyearfilter =
SUMMARIZE ( topthreecost, Data[Product] )
RETURN
CALCULATE (
SUM ( Data[Costs] ),
KEEPFILTERS ( ( TREATAS ( withoutyearfilter, Data[Product] ) ) )
)
 
_Turnover: =
VAR yearselect = 2021
VAR newtable =
FILTER ( ALL ( Data ), Data[Year] = yearselect )
VAR topthreecost =
TOPN ( 3, newtable, Data[Costs], DESC )
VAR withoutyearfilter =
SUMMARIZE ( topthreecost, Data[Product] )
RETURN
CALCULATE (
SUM ( Data[Turnover] ),
KEEPFILTERS ( ( TREATAS ( withoutyearfilter, Data[Product] ) ) )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thanks @Jihwan_Kim, that's almost what I wanted. However when I apply it to my dataset it doesn't show the top3 consistently. I assume this is because in my dataset there can be multiple rows with the same product per year. I don't seem to be able to attach .pbix here, so here is a picture of my data:

 

sim_kay7_0-1638959151794.png

 

How can I modify your code to make it work on this data as well?

 

Best Regards

Simkay

@Jihwan_Kim I added an intermediate step to summarize the costs per product per year.

 

Now it works. Thanks for your help!

 

Here is the full solution:

sim_kay7_0-1638963672656.png

 

Cheers, Simkay

 

VahidDM
Super User
Super User

Hi @sim_kay7 

 

You can create another table with DAX and use that or create measure for those items and filter them to just show the top 3, then add measure as a value.

Share you PBIX file or Sample of data to be able to work on it.

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.