Rank a number closest to zero, but rank positive numbers higher

mrmlg1980

New Member
Joined
Sep 29, 2023
Messages
3
Office Version
  1. 365
Hi, i am trying to write a rank formula that ranks the percentage closest to zero. For example, i have +0.1%, -0.1%, +0.2% & -0.2%. The number closest to zero is +0.1% & -0.1%, but the positive number is better, so 1st should be +0.1%, 2nd -0.1%, 3rd +0.2%, 4th -0.2%. I can rank closest to zero using ABS formula, but i can't get the formula to then treat the positive number as a higher ranking. Any ideas?? Thanks!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
If A2:A5 is data range formula is
Excel Formula:
=INDEX(A$2:A$5,AGGREGATE(15,6,ROW($A$2:$A$5)/((ABS($A$2:$A$5)-(($A$2:$A$5>0)*(10^-6*ROW($A$2:$A$5))))=AGGREGATE(15,6,ABS($A$2:$A$5)-(($A$2:$A$5>0)*(10^-6*ROW($A$2:$A$5))),ROWS($C$2:$C2))),1)-ROW($C$1))
copy down.
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Excel for MS 365! Thank you
 
Upvote 0
Thanks for that.
How about
Excel Formula:
=XMATCH(ABS(A2),SORT(ABS($A$2:$A$7)))+IF(A2<0,SIGN(COUNTIF(A:A,-A2)),0)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Simpler formula
Excel Formula:
=IFERROR(AGGREGATE(15,6,($A$2:$A$5)/((ABS($A$2:$A$5)-(($A$2:$A$5>0)*(10^-6*ROW($A$2:$A$5))))=AGGREGATE(15,6,ABS($A$2:$A$5)-(($A$2:$A$5>0)*(10^-6*ROW($A$2:$A$5))),ROWS($C$2:$C2))),1),"")
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,247
Members
449,093
Latest member
Vincent Khandagale

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top