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.
I am using RANKX to display a rank based on a value. The value can either be positive or negative, but there will be some with no value (which will show zero). I would like to be able to rank based on highest to lowest, then putting all the blank/0's at the end.
Current:
Value Rank
5 1
2 2
0 (BLANK) 3
-1 4
-2 5
Desired Outcome
5 1
2 2
-1 3
-2 4
0 (BLANK) 5
Solved! Go to Solution.
Hi @thampton ,
We can create a measure using following formula to meet your requirement:
Rank = VAR t = FILTER ( ALLSELECTED ( 'Table' ), [Value] + 0 <> 0 ) RETURN IF ( MAX ( 'Table'[Value] ) + 0 <> 0, RANKX ( t, CALCULATE ( MAX ( 'Table'[Value] ) ),, DESC ), CALCULATE ( DISTINCTCOUNTNOBLANK ( 'Table'[Value] ), t ) + 1 )
We can also create a calculate column using following formula
RankColumn = VAR t = FILTER ( 'Table' , [Value] + 0 <> 0 ) RETURN IF ( [Value] + 0 <> 0, RANKX ( t, [Value],, DESC ), CALCULATE ( DISTINCTCOUNTNOBLANK ( 'Table'[Value] ), t ) + 1 )
BTW, pbix as attached.
Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @thampton ,
How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?
Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @thampton ,
We can create a measure using following formula to meet your requirement:
Rank = VAR t = FILTER ( ALLSELECTED ( 'Table' ), [Value] + 0 <> 0 ) RETURN IF ( MAX ( 'Table'[Value] ) + 0 <> 0, RANKX ( t, CALCULATE ( MAX ( 'Table'[Value] ) ),, DESC ), CALCULATE ( DISTINCTCOUNTNOBLANK ( 'Table'[Value] ), t ) + 1 )
We can also create a calculate column using following formula
RankColumn = VAR t = FILTER ( 'Table' , [Value] + 0 <> 0 ) RETURN IF ( [Value] + 0 <> 0, RANKX ( t, [Value],, DESC ), CALCULATE ( DISTINCTCOUNTNOBLANK ( 'Table'[Value] ), t ) + 1 )
BTW, pbix as attached.
Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @thampton not sure how did you want to solve this problem. Were you hoping to have a solution through a table, measure or calculated column?
I have done it by doing a table and measure
Soucre Data
Column1
5 |
2 |
0 |
-1 |
-2 |
0 |
Table
CALTBL = VAR _1 = FILTER(ALLNOBLANKROW('Table'[Column1]),'Table'[Column1]+0<>0) VAR _2 = ADDCOLUMNS(_1,"Rank",RANKX(_1,[Column1]+0)) VAR _3 = MAXX(_2,[Rank])+1 VAR _4 = FILTER('Table','Table'[Column1]+0+1=1) VAR _5 = ADDCOLUMNS(_4,"Rank",_3) VAR _6 = UNION(_2,_5) RETURN _6
Through a measure
Measure: = VAR _11 = RANKX(FILTER(ALLNOBLANKROW('Table'[Column1]),'Table'[Column1]+0<>0),CALCULATE(SUM('Table'[Column1])),,DESC) VAR _1 = FILTER(ALLNOBLANKROW('Table'[Column1]),'Table'[Column1]+0<>0) VAR _2 = ADDCOLUMNS(_1,"Rank",RANKX(_1,[Column1]+0)) VAR _3 = MAXX(_2,[Rank])+1 VAR _14 =SUM('Table'[Column1]) VAR _15 = IF(ISBLANK(_14)=True||_14=0,_3,_11) RETURN _15
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
111 | |
92 | |
84 | |
66 |