sorting - Ranking in Excel, when I want the top n I get the top n+1 (or n+x) -
i have list in excel , i'd select higher 3 results, , 3. seems easy conditional formatting in example:
1 | 2 | 3 | 4 | 5 | 6 44 | 78 | 98 | 45 | 52 | 98
where 2nd, 3rd , 6th number highlighted.
the problem appears this:
1 | 2 | 3 | 4 | 5 | 6 44 | 78 | 78 | 45 | 87 | 98
excel highlight 2nd, 3rd, 5th , 6th number, because first 2 (the third on sorted list) equal. how can make excel select 1 of them?
(the solution doesn't need use conditional formatting, tools available on excel can used, formulas vb, simplicity it's desirable).
for conditional formatting, need break tie. 1 way count number of times value appears in previous comparisons.
this change conditional formula to
=(rank(a2,$a$2:$f$2)+countif($a$2:a$2,a2)-1)<=3
note absolute positions used in cases, , relative in others.
breakdown:
rank(a2,$a$2:$f$2)
- rank formula. know one, you're using now
countif($a$2:a$2,a2)
- count number of times value appears - note reference not have $ in front of a
after colon - ensure range gets bigger process formula along row (1st count: a2:a2, 2nd count: a2:b2, etc)
-1
- count match 1 number (itself)
so, second example,
44 78 78 45 87 98
the new ranks are
6 3 4 5 2 1
and formulas convert
=rank(a2,$a$2:$f$2)+countif($a$2:a$2,a2)-1
=rank(b2,$a$2:$f$2)+countif($a$2:b$2,b2)-1
=rank(c2,$a$2:$f$2)+countif($a$2:c$2,c2)-1
=rank(d2,$a$2:$f$2)+countif($a$2:d$2,d2)-1
=rank(e2,$a$2:$f$2)+countif($a$2:e$2,e2)-1
=rank(f2,$a$2:$f$2)+countif($a$2:f$2,f2)-1
for conditional formatting
Comments
Post a Comment