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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
wwolfg
Frequent Visitor

Dynamically filter graph depending on Rank

Hi,

 

I want to create 4 time series graph that represent the rank 1, rank 2, rank 3 and rank 4. 

 

I tried several ways with no success.

 

First I make a measure for the scrap quantity produced: 

Merma Kg = SUM(Merma[Quantity])
 

ThenI make the ranking, which works apparently fine in a table:

Rank Procesos Merma =RANKX(ALLSELECTED(Merma[Proceso]),CALCULATE([Merma Kg]))
 
Then I made 1 measure for each rank For example for the rank 1 and 2:
 
Merma Rank 1 = if([Rank Procesos Merma]=1,[Merma Kg],BLANK())
Merma Rank 2= if([Rank Procesos Merma]=2,[Merma Kg],BLANK())
 
But it does not work at all. I watched this video and made some changes and they work well in a table but not in the graph.
 
Merma Top 1 =
if(ISFILTERED(Merma[Proceso]),if([Rank Procesos Merma]=1,[Merma Kg],BLANK()),CALCULATE([Merma Kg],TOPN(1,VALUES(Merma[Proceso]),[Merma Kg]))) This does work but it is because I am using top 1, but it does not work when I use rank 2, etc.
 
Here is the link for some sample data and this is a summarized table of the data, and how I want to visualize it
 
ProcesoMerma KgRank Procesos Merma
Proceso 5209631
Proceso 4187812
Proceso 10175373
Proceso 3135584
Proceso 2104935
Proceso 196716
Proceso 793427
Proceso 981228
Proceso 627509
Proceso 8127210
 
wwolfg_0-1696628892462.png

 


 

I want to be able to dinamycally calculate the ranks and visualizations when I change the date.
 
I appreciate your help beforehand.
 
Walter
 
 
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Your rank will be calculated on different filter contexts.  Process 5 is only #1 overall, but not for the individual rows.  So you would have to do two steps 

- find the process that is ranked #1 overall

- show the items for that process.

 

Merma Rank 1 = 
var a = summarize(ALLSELECTED(Merma),[Proceso],"sm",[Merma Kg])
var b = maxx(TOPN(1,a,[sm]),[Proceso])
return calculate([Merma Kg],Merma[Proceso]=b)

For Rank 2 you need to do some extra gymnastics

Merma Rank 2 = 
var a = summarize(ALLSELECTED(Merma),[Proceso],"sm",[Merma Kg])
var b = maxx(TOPN(1,TOPN(2,a,[sm]),[sm],ASC),[Proceso])
return calculate([Merma Kg],Merma[Proceso]=b)

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Your rank will be calculated on different filter contexts.  Process 5 is only #1 overall, but not for the individual rows.  So you would have to do two steps 

- find the process that is ranked #1 overall

- show the items for that process.

 

Merma Rank 1 = 
var a = summarize(ALLSELECTED(Merma),[Proceso],"sm",[Merma Kg])
var b = maxx(TOPN(1,a,[sm]),[Proceso])
return calculate([Merma Kg],Merma[Proceso]=b)

For Rank 2 you need to do some extra gymnastics

Merma Rank 2 = 
var a = summarize(ALLSELECTED(Merma),[Proceso],"sm",[Merma Kg])
var b = maxx(TOPN(1,TOPN(2,a,[sm]),[sm],ASC),[Proceso])
return calculate([Merma Kg],Merma[Proceso]=b)

Thank you, it worked perfect. I appreaciate very much your help.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.