Ranking Changes in Quantity (whether they are positive or negative)

ellison

Active Member
Joined
Aug 1, 2012
Messages
356
Office Version
  1. 365
Platform
  1. Windows
Hi, we are trying to rank changes in quantity.
Some of the differences may be positive and some may be negative (i.e. some of the qty's may go up, some may come down), but what we are interested in ranking is the actual difference (not whether it is +ve or -ve)
Some of the data contains blanks, which actually should be zero's (but that's on the next round of tidying up duties for me!)

Hopefully this makes it a little bit clearer....


excel-ranking-changes-in-qty-question.xlsx
ABCDEFG
1Qty-AQty-B+ve or -veDifferenceRankManual Notes (not needed) Regarding the "difference between A & B is…"
25050same05...is 0, so this will be the smallest difference
35positive54...is 5, which is the second smallest difference NB some of the figures are blank (and blanks represent a "0")
410050positive501...is "50" which is the largest, therefore ranked highest = Number 1
58545positive402...is "40" which is the 2nd largest, therefore rank = 2
63575negative-402is "still 40" (regardless of it is positive or negative) which is the equal 2nd largest, therefore rank = 2
73565negative-303Difference between A & B is "30" which is the equal 3rd largest, therefore rank = 3
Sheet1
Cell Formulas
RangeFormula
C2:C7C2=IF(D2>0,"positive",IF(D2<0,"negative","same"))
D2:D7D2=+A2-B2



Huge thanks for taking a look!






Huge thanks for
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,

D2 will be:
Excel Formula:
=ABS(A2-B2)
E2 will be:
Excel Formula:
=RANK(D2,$D$2:$D$7,0)
 
Upvote 0
Absolutely brilliant!
Just one fly in the ointment left...

In terms of the rankings:

Where the difference 40 occurs twice, they are both (rightly!) ranked number 2.

But the next biggest difference is 30, and we'd like that to be ranked number 3 (rather than number 4).

Is there are a way to deal with that?
 
Upvote 0
Another way

23 11 30.xlsm
ABDE
1Qty-AQty-BDifferenceRank
2505005
3554
410050501
58545402
63575402
73565303
Rank ABS
Cell Formulas
RangeFormula
D2:D7D2=ABS(A2-B2)
E2:E7E2=COUNT(UNIQUE(FILTER(D$2:D$7,D$2:D$7>D2,"")))+1
 
Upvote 0
Hi all, huge thanks for working out those brilliant solutions.... :)
And for what it's worth both Peter's and Phuocs answers both work.
(And a big thank you to Flashbond too!)
 
Upvote 0
Eh heheh it is a bit sketchy but it works :)
Excel Formula:
=IF(MOD(ROW(),2)=0,CEILING(RANK.AVG(D2,$D$2:$D$7,0),1),FLOOR(RANK.AVG(D2,$D$2:$D$7,0),1))
 
Upvote 0
Hi Peter :)
Not if the previous ones do. ;)
Check rows 5 & 6 and ..
It was working perfectly fine for me. I use RANK.ORT function. Maybe my translation to English was wrong. Turkish ORT is ORTALAMA which means AVERAGE in English. RANK.AVG was the closest match I could find. I have no chance to test with English function names.
1701342369826.png

Although, I found another flaw with my code. It returns the wrong result if both duplicates are in even-number rows.
 
Upvote 0
It was working perfectly fine for me. I use RANK.ORT function. Maybe my translation to English was wrong.
Hmm, interesting. This is what I get when I use the formula from post 7. Rows 4 & 5 are correct but all others are 1 off.

23 11 30.xlsm
DEF
1DifferenceRankPost #7
2056
3545
45011
54022
64023
73034
Rank ABS
Cell Formulas
RangeFormula
D2:D7D2=ABS(A2-B2)
E2:E7E2=COUNT(UNIQUE(FILTER(D$2:D$7,D$2:D$7>D2,"")))+1
F2:F7F2=IF(MOD(ROW(),2)=0,CEILING(RANK.AVG(D2,$D$2:$D$7,0),1),FLOOR(RANK.AVG(D2,$D$2:$D$7,0),1))
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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