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
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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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

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.