简体   繁体   English

在Excel中仅对正数进行排序-从大到小,仅对负数进行排序-在Excel中从小到大

[英]Sorting only positive numbers – Largest to Smallest & Sorting only negative numbers – Smallest to largest in excel

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()),"") = 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. 我有3000多个行的数据,只需要前20-30个正数和前20-30个负数。

Any help will be greatly appreciated. 任何帮助将不胜感激。

Looking forward for the positive response. 期待积极的回应。

Thanks, Ganesh 谢谢,Ganesh

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: 将此公式放在“正值”列的第2行中,并向下拖动任意数量的项目以使其突出显示:

=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. 请注意,由于我们从第2行开始,因此我使用ROW()-1而不是ROW(),因此第2行应包含最大数量,而不是第二个最大数量。 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 #]. 我还强迫它显示0,否则将显示一个负数(即:如果您想要最大的5个数字,而第5个最大的数字是负号)。

The formula for showing the smallest negative formulas is nearly identical: 用于显示最小否定公式的公式几乎相同:

=IFERROR(MIN(0,SMALL(A:A,ROW()-1)),"")

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. 这可以通过使用LARGE(range,k)SMALL(range,k)公式轻松实现,它们分别为您提供范围中第k个最大或第k个最小的数字。

you can use them in combination with the ROW([range]) function which gives you the row number of the desired range. 您可以将它们与ROW([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. 如果将ROW(A1)用作上述函数的k ,则向下拖动公式将产生ROW(A2)ROW(A3)等,从而为每一行提供所需的k值。

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. 这种方法有一个问题-如果您想获得20个正数,但只说范围内有10个正数,则公式将为您提供20个正数,而不管它们是正数还是负数。 however, i believe in your case, this is the easiest and fastest solution and this shouldn't be a big deal. 但是,我相信您的情况,这是最简单,最快的解决方案,应该没什么大不了的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM