根据唯一值获取最大值

问题描述:

我在 Excel 中有两列如下:

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

如何编写一个命令来返回 col2 中对应于 col1 中每个唯一值的最大值?

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

所以这里我需要写一个命令来获取2316.

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

我在这里展示的数据是假的;我的实际数据集中的 col1 中有 600 个唯一值.

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

数据透视表:excel 中最未被充分利用且最强大的功能.

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

  • 文件菜单:
  • 插入
  • 数据透视表
  • 选择范围
  • 如下图所示填写

循序渐进:

  • 将光标置于工作表上所有数据右侧的单元格中.
  • 从菜单中选择插入
  • 选择数据透视表图标
  • 从图标的弹出窗口中选择数据透视表
  • 使用按钮选择包含的单元格范围(2 列中的所有 600 多行)(或只需输入 $A:$B)
  • 选择确定
  • 数据透视表字段列表出现在右侧:
  • 将第 1 行拖放到行标签中.
  • 将第 2 行拖放到值区域.
  • 左键单击...第 2 行"
  • 选择值字段设置
  • 选择Max"而不是count或sum
  • 选择确定",您应该会得到想要的结果.

数据透视表将为第 1 行中的每个唯一值找到第 2 行中的最大值,这正是我相信您所追求的.

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.