SUMPRODUCT to get row +1

白昼怎懂夜的黑 提交于 2021-01-29 01:55:31

问题


I have a table like below:

12/7/2012   A   B   
                     100    

12/21/2012  A   I   
                     20

12/23/2012  A   I   
                     25     

12/1/2013   A   I   
                     20     

12/1/2014   A   I   
                     20

I want to get the value in column D where column B is "A" and column C is "I". I used a sumproduct to get the value in column D, but I need to go down 1 row from wherever column B is "A" and column C is "I". This is my formula:

=SUMPRODUCT(--(B:B="A"),--(C:C="I"),F:F+1). 

It should return a value of 85, but it returns a value of 4.


回答1:


You could use

=SUM((B1:B10="A")*(C1:C10="I")*(D2:D11))

as an array formula with CtrlShiftEnter

or

=SUMPRODUCT(--(B1:B10="A"),--(C1:C10="I"),(D2:D11))

and extend the range as far as you need to.

What happens with your formula

=SUMPRODUCT(--(B:B="A"),--(C:C="I"),D:D+1)

is that it is just adding one to each row in column D. D1, D3, D5 and D7 are empty cells so count as zero. So for the four matching rows it is adding one to the total and the result is 4.




回答2:


If =SUMPRODUCT(--(B:B="A"),--(C:C="I"),D:D+1) worked it may just be coincidence. You might check by taking a copy and in that deleting D1 with Shift cells up then applying:

=SUMIFS(D:D,B:B,"A",C:C,"I")  

Or of you don't have SUMIFS filter to delete rows that do not contain a date in ColumnA, A in ColumnB and I in ColumnC, then summing ColumnD.

With SUMIFS an alternative to @Tom's SUMPRODUCT might be:

=SUMIFS(D2:D1000001,B1:B1000000,"A",C1:C1000000,"I")


来源:https://stackoverflow.com/questions/32936369/sumproduct-to-get-row-1

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