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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sim_kay7
New Member

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.


Go to My LinkedIn Page


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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors