简体   繁体   中英

Using excel to count with conditions

I have an excel sheet that looks like this (with many more columns and rows of course):

condition a condition b condition c condition d result (a,b) result (c,d)
yes no yes no 0 1
no no no yes 0 1
yes yes no no 1 0

...

Now, I only want to separately count the occurrences of either a or b or both are occurring per row , but want to exclude all instances where either a or b (or both) are occurring together with c or d, since I want to count the occurrences where either c or d or both are apperearing separetely. I have toyed around with the idea of using the countifs , but my problem is that I want to count every row separately, so if a and b occur together I only want to count them once, so if I applied countifs to all the colums together, it would count all instances of yes in the a and b column.

For example here in the first row, I would get a 1 for c,d and a 0 for a,b since while there is a yes for a in the first row, there is also one for c. In the second row, we only have yes for d so it's easy that it's easyily 1 for c,d and 0 for a,b.

And finally in the third row we only have a,b both yes, so it's 1 for a,b since I want to know the occurence per row, and since there is no for both c and d, and so it's 0 for c,d since both are no.

Does anyone know how to solve this in excel? Thank you all for your help

Use AND and OR (COLUMN E):

=--AND(AND(C2<>"yes",D2<>"yes"),OR(A2="yes",B2="yes"))

And (COLUMN F)

=--OR(D2="yes",C2="yes")

在此处输入图像描述

If you want to count without the helper columns:

A,B:

=SUMPRODUCT(((C2:C4<>"yes")*(D2:D4<>"yes"))*((A2:A4="yes")+(B2:B4="yes")>0))

C,D:

=SUMPRODUCT(--((C2:C4="yes")+(D2:D4="Yes")>0))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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