Reputation: 95
I have a set of data, composed of positive and negative numbers. For simplicity let’s say the data looks like this:
I would like to sort the data by only positive and negative numbers for “only top 3 customers”. So the report would look like this:
I have been experimenting with formulas like this, but this formula doesn't help me achieving the results. =IFERROR(LARGE(IF(A2:A13>0,A2:A13,""),ROW()),"")
I have data for more than 3000 lines and need only top 20-30 positive numbers and Top 20-30 negative numbers.
Any help will be greatly appreciated.
Looking forward for the positive response.
Thanks, Ganesh
Upvotes: 0
Views: 1064
Reputation: 3823
You are overcomplicating your formulas above - but you are on the right track.
Put this formula in row 2 of the Positive column, and drag down for as many items as you want to highlight:
=IFERROR(MAX(0,LARGE(A:A,ROW()-1)),"")
Note that I have used ROW()-1, instead of ROW(), because we are starting at row 2, and therefore row 2 should contain the largest amount, not the 2nd largest amount. I have also forced it to show a 0 if it would otherwise show a negative number [ie: if you want the largest 5 numbers, and the 5th largest is a negative #].
The formula for showing the smallest negative formulas is nearly identical:
=IFERROR(MIN(0,SMALL(A:A,ROW()-1)),"")
Upvotes: 1
Reputation: 2388
this can easily be achieved by using LARGE(range,k)
and SMALL(range,k)
formulas which give you the k-th largest or the k-th smallest number in a range, respectively.
you can use them in combination with the ROW([range])
function which gives you the row number of the desired range. if you use ROW(A1)
as the k
for the aforementioned functions, then dragging the formulas down will yield ROW(A2)
, ROW(A3)
and so on, which for each row will give you the desired k
value.
so the formula will look like this:
top positive numbers:
=LARGE($A$2:$A$13,ROW(A1))
bottom negative numbers:
=SMALL($A$2:$A$13,ROW(A1))
then you just need to drag the formula down to the nearby cells and you will get your result.
there's one problem with this approach - if you want to get 20 top positive numbers but only have, say, 10 positive numbers in the range, the formula will give you 20 top numbers regardless if they're positive or negative. however, i believe in your case, this is the easiest and fastest solution and this shouldn't be a big deal.
Upvotes: 0