Forum Discussion
IF/AND Function?
STRACTROOP You could simplify the process by having a single Answer column, where 1 = Yes and 0 = No. For example:
Name | Question | Answer |
Tom | 1 | 1 |
Tom | 2 | 0 |
Tom | 3 | 1 |
Tom | 4 | 1 |
Jerry | 1 | 0 |
Jerry | 2 | 0 |
Jerry | 3 | 1 |
Jerry | 4 | 1 |
The COUNTIFS function can then be used to get a count of all Yes/No answers for each question. For example, to count all Yes answers for question 3:
=COUNTIFS(B2:B113, 3, C2:C113, 1)
And, to count all No answers for question 3:
=COUNTIFS(B2:B113, 3, C2:C113, 0)
With MS365, the results can also be made to spill dynamically for all questions and answers using TOCOL & UNIQUE for the question criteria and TOROW & SORT/UNIQUE for the answer criteria:
=COUNTIFS(B2:B113, TOCOL(UNIQUE(B2:B113), 1), C2:C113, TOROW(SORT(UNIQUE(C2:C113),, -1), 1))
The result in this case would be a 2x4 array representing a count of all Yes and No answers for each question. To create a single cell report, complete with question numbers as well as headers, use the following:
=LET(
q, TOCOL(UNIQUE(B2:B113), 1),
a, TOROW(SORT(UNIQUE(C2:C113),, -1), 1),
VSTACK({"Question","Yes","No"}, HSTACK(q, COUNTIFS(B2:B113, q, C2:C113, a))))
Adjust the range references to meet your needs. 🙂