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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
cdcphist
Frequent Visitor

Rankx with filter ranks all rows

Hi,

 

I have the following data (an example):

 

valuecompanycategoryrank
50AS37
54AS41
40AS33
33AS30
50AS37
260AS60
295AS63
50AS37
25AS23
17AS18
100AS48
65AS45
 AS1
120AS55
 AS1
100AS48
16AS16
 AS1
 AS1
45AS36
150AS57
65AS45
 AS1
18AS19
25AS23
20AS20
40AS33
30AS28
15AS14
100AS48
20AS20
280AS62
55AS42
 AS1
200AS58
30AS28
 AS1
16AS16
100AS48
15AS14
100AS48
60AS43
60AS43
120AS55
10AS13
0AS1
33AS30
40AS33
50AS37
275AS61
250AS59
27AS27
100AS48
25AS23
38AS32
100AS48
25AS23
93AS47
20AS20
 AS1
 AS1
 AS1
 AS1

 

Rank is a calculated column with the following code:

 

rank = 
VAR currentcompany =table[company]
VAR currentcategory =table[category]
var currentvalue=table[value]
RETURN
RANKX (FILTER ( table, table[company] = currentcompany && table[category] = currentcategory && not(isblank(currentvalue))), table[value_FE],,ASC)

The problem is that even with the filter on the value column, the ranking still  happens on those values. Ideally, i want for some rows to not be ranked at all, specifically, the rows where there is no value. Is this possible?

 

Thank you.

2 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@cdcphist 

Add the column as follows:

 

rank = 
VAR currentcompany ='Table'[company]
VAR currentcategory ='Table'[category]
var currentvalue='Table'[value]
RETURN
IF(
    'Table'[value] <> BLANK(),
    RANKX (FILTER ( 'Table', 'Table'[company] = currentcompany && 'Table'[category] = currentcategory && 'Table'[value]<> BLANK()), 'Table'[value],,ASC)
)

 

Fowmy_0-1622630145947.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

Jihwan_Kim
Super User
Super User

Hi, @cdcphist 

Please try something like the below.

 

Picture2.png

 

rank CC =
VAR currentC = 'Table'[company]
VAR cuurentCat = 'Table'[category]
RETURN
IF (
ISBLANK ( 'Table'[value] ),
BLANK (),
RANKX (
FILTER (
'Table',
'Table'[company] = currentC
&& 'Table'[category] = cuurentCat
&& NOT ISBLANK ( 'Table'[value] )
),
'Table'[value],
,
ASC
)
)

 

 

Hi, My name is Jihwan Kim.

 

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

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


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.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi, @cdcphist 

Please try something like the below.

 

Picture2.png

 

rank CC =
VAR currentC = 'Table'[company]
VAR cuurentCat = 'Table'[category]
RETURN
IF (
ISBLANK ( 'Table'[value] ),
BLANK (),
RANKX (
FILTER (
'Table',
'Table'[company] = currentC
&& 'Table'[category] = cuurentCat
&& NOT ISBLANK ( 'Table'[value] )
),
'Table'[value],
,
ASC
)
)

 

 

Hi, My name is Jihwan Kim.

 

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

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


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.
Fowmy
Super User
Super User

@cdcphist 

Add the column as follows:

 

rank = 
VAR currentcompany ='Table'[company]
VAR currentcategory ='Table'[category]
var currentvalue='Table'[value]
RETURN
IF(
    'Table'[value] <> BLANK(),
    RANKX (FILTER ( 'Table', 'Table'[company] = currentcompany && 'Table'[category] = currentcategory && 'Table'[value]<> BLANK()), 'Table'[value],,ASC)
)

 

Fowmy_0-1622630145947.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

amitchandak
Super User
Super User

@cdcphist , only a measure can respond to slicer/filter . Create a measure Rank

 

Try like

 

Rank =
VAR currentcompany =table[company]
VAR currentcategory =table[category]
var currentvalue=table[value]
RETURN
RANKX (FILTER ( allselected(table[company],table[category]), table[company] = max(table[company]) && not(isblank(table[value]))), calculate(sym(table[value_FE])),,ASC)

 

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors