Get maximum value based on unique values

杀马特。学长 韩版系。学妹 提交于 2019-12-02 13:34:57

问题


I have two columns in Excel as follows:

col1  col2

1     10
1     22
1     11
1     23
1     14
2     16
2     12
2     10
2     9

How do I write a command to returns the maximum value from col2 corresponding to each unique value in col1?

So here I need to write a command to get 23 and 16.

The data I have shown here are dummies; I have 600 unique values in col1 in my actual data set.


回答1:


Pivot tables: the single most underutilized and powerful feature of excel.

  • File menu:
  • Insert
  • Pivot Table
  • Select range
  • Fill in as indicated in image below

Step by Step:

  • Place cursor in cell to right of all data on sheet.
  • Select insert from menu
  • select pivot table icon
  • select pivot table from pop-up of icon
  • use the button to select the range of cells included (all 600+ rows in 2 columns) (or just enter $A:$B)
  • select ok
  • A pivot table field list appears on the right:
  • Drag and drop row 1 into row labels.
  • drag and drop row 2 into values area.
  • left click on "... of Row 2"
  • select value field settings
  • select "Max" instead of count or sum
  • select ok and you should have desired results.

The pivot table will find the max value in row 2 for each unique value in row 1 which is what I believe you are after.




回答2:


Even if a solution has been found. I think it is too complicated and oversized to use the pivot for this and it might not be possible in all scenarios. Here is one that can be found searching the internet for "max if excel" (e.g. see here; adapted)

{=MAX(IF(A:A=A1,B:B))}

Attention! This is an array formula, you have to enter it without the curly brackets and then press Ctrl+Shift+Enter to submit the formula.




回答3:


Since the left hand values seem to be in order, Subtotal should work.



来源:https://stackoverflow.com/questions/18406328/get-maximum-value-based-on-unique-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!