Countif 1 and -1 in filter

前端 未结 2 878
自闭症患者
自闭症患者 2021-01-21 21:15

I am trying to count 1 and -1 in filtered data. The count for -1 is correct but for 1 it includes -1 as well and shows the count which is incorrect. If you look at the image att

2条回答
  •  萌比男神i
    2021-01-21 22:01

    Small example:

    Formula in D1:

    =SUMPRODUCT(SUBTOTAL(3,OFFSET(B2:B7,ROW(B2:B7)-ROW(B2),0,1)),--(B2:B7=1))
    

    Formula in F1:

    =SUMPRODUCT(SUBTOTAL(3,OFFSET(B2:B7,ROW(B2:B7)-ROW(B2),0,1)),--(B2:B7=-1))
    

    Result


    If you can't use the above because of error values as per your comment, one thing you could do is to build an array of values with some IF statements like so:

    =SUMPRODUCT(SUBTOTAL(3,OFFSET(B2:B7,ROW(B2:B7)-ROW(B2),0,1)),IF(ISNUMBER(B2:B7),IF(B2:B7=1,1),0))
    

    and:

    =SUMPRODUCT(SUBTOTAL(3,OFFSET(B2:B7,ROW(B2:B7)-ROW(B2),0,1)),IF(ISNUMBER(B2:B7),IF(B2:B7=-1,1),0))
    

    Both formula entered as arrayformula!

提交回复
热议问题