How to use ARRAYFORMULA to count the values of each row

How to use ARRAYFORMULA to count the values of each row
typescript
Ethan Jackson

I made a sheet to use as a test checker. Each test covers different domains. I can count all correct answers using SUMPRODUCT, but when I sort items by domain, the formula stops working. What formula should I use instead?
*first picture referring to the total raw score

=ArrayFormula(SUMPRODUCT(($F$1:$BY$1=$F$4:$BY$4)*($F$2:$BY$2=F5:BY5)))

second picture sorted by domains per test

=SUMPRODUCT($DP$1:$EG$1=$DP$4:$EG$4)*(DP2:EG2=DP5:EG5)

thank you! i want to count the scores for each domain. but I cant do it again since it says use ARRAYFORMULA

Answer

You can try this formula using Map:

=SUM(MAP($F$2:$Q$2, F5:Q5, LAMBDA(x, y, IF(x=y, 1, 0))))

For a dynamic formula, you can try this:

=BYROW(F5:Q, LAMBDA(row, IF(COUNTA(row) = 0, "", SUM(MAP($F$2:$Q$2, row, LAMBDA(x, y, IF(x=y, 1, 0)))))))

Sample Output:

Question #Q1Q2Q3Q4Q5Q6Q7Q8Q9Q10Q11Q12
AnswerECDHBFCFDKAH
Grade levelQ1Q2Q3Q4Q5Q6Q7Q8Q9Q10Q11Q12Total Score
aEGDHBFCFDAAH10
ASAAAAAAAAFF0
EGDHBFCFDAAH10
E1

Reference/s: Byrow , CountA

Related Articles