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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
czaldumbide
Helper II
Helper II

Ranking a parameter on filtered grouped table

Hi!

I'm having trouble writing a measure that ranks a parameter. Essentially, the user inputs a numeric value as a parameter and my report should output it's ranking based on grouped sales by week and client. Filters can be applied. 


To make this exercise easier I have attached a picture of my report page and a sample PBI file. The column highlighted in red is the one NOT working properly. Would appreciate any tips on how to modify it.

Since my parameter might not exist in my grouped table, I first created a measure that will return the closest value in order to then calculate the ranking. This works fine. 

Closest amount to parameter = 

var threshold = Parameter[Parameter Value] ---- returns parameter inputed by the user

VAR SourceTable =
    ADDCOLUMNS ( ALLSELECTED ( Sales[Weeknum + ClientID]), "@Amt", [Sales] ) 
    ----- temp table adding sales amount, grouped by weeknum and client 

var closest_above =
    MINX(FILTER(SourceTable, [@Amt]>= threshold), [@Amt])

var closest_below = 
    MAXX(FILTER(SourceTable, [@Amt]<= threshold), [@Amt])

var result =  if(abs(threshold-closest_above) < abs(threshold-closest_below), closest_above, closest_below)

return result


Second measure should return the rank of my parameter based on grouped table. Issue is that its not taking in account slicer filters applied to the report page. Essentially works fine until I select a filter in the slicer 'TransDesc'.

Rank of parameter = 

var SourceTable =
    ADDCOLUMNS( ALLSELECTED ( Sales[Weeknum + ClientID]), "@Amt", [Sales])

var GroupedTable = ADDCOLUMNS(FILTER(SourceTable, [@Amt] <> BLANK()), "@Rank", RANKX(SourceTable, [Sales],,ASC))

var threshold = [Closest amount to parameter]

var result = MINX(FILTER(GroupedTable, [@Amt]= threshold),  [@Rank])
return result

 

 

In example below, I would expect that Rank of parameter = 136
Ranking sample PBI report page.PNG
here is the link:
RankingSample.pbix 
Any help is appreciated!

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

You forgot your Sales>0 filter.  Also note that you can use the [Value]  parameter of RANKX to your advantage.

 

lbendlin_0-1743183680266.png

 

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

You forgot your Sales>0 filter.  Also note that you can use the [Value]  parameter of RANKX to your advantage.

 

lbendlin_0-1743183680266.png

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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