Find count of items in column and add the values from another column

你。 提交于 2019-12-11 13:09:42

问题


I have two columns in a table (A and B). Column A has an item name and Column B has a quantity. I want to sum the quantities for all the items that have the same name. Example:

Item        |  Quantity
------------+----------
Red Hat     |         3
Green Shirt |         9
Red Hat     |         4
Blue Pants  |         6
Blue Pants  |         3
Green Shirt |        12

and I would like to add a column to the table that has this:

Item        |  Quantity  |  Total
------------+------------+-------
Red Hat     |         3  |      7
Green Shirt |         9  |     21
Red Hat     |         4  |      7
Blue Pants  |         6  |      9
Blue Pants  |         3  |      9
Green Shirt |        12  |     21

I want to be able to sort the table by the items that have the most total quantity (keeping it grouped by the item name, so if two items have the same total quantity, I would like them grouped separately).


回答1:


Try the SUMIF function. See http://www.techonthenet.com/excel/formulas/sumif.php for more details.

More specifically, the formula for cell C1 should be:

=SUMIF(A:A,A1,B:B)

Assuming columns A and B are item and quantity respectively.



来源:https://stackoverflow.com/questions/14324308/find-count-of-items-in-column-and-add-the-values-from-another-column

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