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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.

Top Solution Authors