简体   繁体   English

如何在Excel中总结标准?

[英]How to sum over criteria in Excel?

Let's say I have a table of First/Last names and Salaries.I want to compute, for every last name, the sum of the salaries of people with that name.假设我有一个名字/姓氏和薪水表。我想计算每个姓氏的人的薪水总和。

I know how to do that for each name individually using SUMIF, but I was wondering if there is a quick function to produce a table of Last names and Salary sums?我知道如何使用 SUMIF 为每个姓名单独执行此操作,但我想知道是否有一个快速功能可以生成姓氏和工资总额的表格?

Another option would be using a pivot table.另一种选择是使用数据透视表。

  1. On the insert tab, select pivot table在插入选项卡上,选择数据透视表
  2. Use your existing table as the data使用您现有的表作为数据
  3. In the fields select the Last Name and Salary columns在字段中选择Last NameSalary

Let's support you have the salary sheet in sheet1 as below,让我们支持您在 sheet1 中的工资表如下,

在此处输入图片说明

copy column last name value to sheet2.column A, remove duplicate, add a new column as Salary Sum in column B, input a formula as =SUMIF(Sheet1!B:B,Sheet2!A2,Sheet1!C:C) and drop down to all rows, then you can got a salary sum table as below,将列姓氏值复制到 sheet2.column A,删除重复项,在 B 列中添加一个新列作为 Salary Sum,输入公式为 =SUMIF(Sheet1!B:B,Sheet2!A2,Sheet1!C:C) 并删除到所有行,然后你可以得到一个工资总额表,如下所示,

在此处输入图片说明

of course, if the first name/last name is dynamic and unexpected, it would doesn't work.当然,如果名字/姓氏是动态的和意料之外的,它就行不通。 you can drop a button and bind a VBA code to handle it.您可以删除一个按钮并绑定一个 VBA 代码来处理它。

You could use this ARRAY FORMULA: CTRL + SHIFT + ENTER你可以使用 这个数组公式:CTRL + SHIFT + ENTER

=IFERROR(INDEX($A$2:$A$7,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$7),0)),"")

For summing up the corresponding values just use为了总结相应的值,只需使用

=SUMIFS($B$2:$B$7,$A$2:$A$7,D2)

在此处输入图片说明

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

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