SUMIF contains one of elements in array (OR)

风格不统一 提交于 2019-12-02 06:21:52

问题


I have a list of payments where I would like to sum up the costs which description equals to one of the elements in my array.

EMTE     € 120,00 
Bread    € 35,24 
Lidl     € 0,89 
Plus     € 5,19 
Aldi     € 2,29 
Jumbo    € 4,70 

So with an array of {"Lidl", "Aldi"}, It would give me the total of (2,29+0,89) 3,18.

I tried Sum.If, but I don't seem how to use the or statement in it properly and combine it with an array kind of input.


回答1:


Wrap the SUMIF / SUMIFS function in a SUMPRODUCT function to provide an extra level of cyclic calculation.

=SUMPRODUCT(SUMIFS(B:B, A:A, {"Lidl","Aldi"}))

        




回答2:


You could use a pivot table to get the result. The advantage of this solution is that it does not require complex formulas and is easy to change. To create the pivot table:

  • Select your data and use Insert > PivotTable
  • Drag your first column to ROW, your second column to VALUES
  • Make sure the VALUES are aggregated using a SUM
  • In the top row of your PivotTable you see a DropDown that allows you to select the values that should be included in your report
  • Make sure a grand total is displayed for all rows


来源:https://stackoverflow.com/questions/34530624/sumif-contains-one-of-elements-in-array-or

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