Using ARRAYFORMULA to calculate row totals in Google Sheets

I’m working with a Google Forms response sheet where I need to automatically score submissions. My setup has the correct answers stored in row 2 like this:

      A               B             C
1
2 CorrectAns1, CorrectAns2, CorrectAns3....

I’ve successfully used ARRAYFORMULA to check each answer against the correct ones in additional columns:

=IF(ARRAYFORMULA(B3:B=B2),1,0)

This works perfectly and gives me 1 for correct answers and 0 for wrong ones.

Now I want to create a final column that sums up all the correct answers (all the 1’s) for each row. I tried this approach:

=IF(ARRAYFORMULA(<some condition>),sum(E3:Y3),0)

The problem is this formula calculates the same range E3:Y3 for every row instead of adjusting to the current row like E4:Y4, E5:Y5, etc. I need the sum to work dynamically for each new form submission row.

I’ve tried various modifications like changing the range to E3:E or putting everything inside ARRAYFORMULA but nothing works. How can I make the sum formula work properly for each individual row?

You’re hitting the classic ARRAYFORMULA issue where SUM won’t adjust row ranges dynamically. Skip SUM and use multiplication instead: =ARRAYFORMULA(IF(LEN(A3:A)>0,(E3:E*1)+(F3:F*1)+(G3:G*1)+(H3:H*1),"")) - extend this for all your scoring columns. Multiplying by 1 converts TRUE/FALSE or 1/0 values, then adding gives you the total. ARRAYFORMULA handles this automatically for each row without messy MMULT functions. I use this all the time for quiz scoring and it works great with new form submissions. Just replace SUM with direct addition of each column - ARRAYFORMULA can handle that row by row.

The Problem:

You’re trying to create a final column in your Google Sheet that sums the correct answers (represented by 1s) for each row from your automatically generated scoring columns. Your current SUM formula within ARRAYFORMULA calculates the same range for every row, instead of dynamically adjusting to the current row. You need a solution that correctly sums the 1s for each row, automatically updating as new form submissions are added.

:thinking: Understanding the “Why” (The Root Cause):

The SUM function within ARRAYFORMULA doesn’t automatically adjust its range for each row. It calculates the sum based on the initially specified range (e.g., E3:Y3) and replicates that result for every row. This is a fundamental limitation of how ARRAYFORMULA handles range references within its internal calculations. To solve this, you must use a formula that inherently works row-by-row, effectively creating a dynamic range for each row without explicitly defining them. Simple SUM cannot do that inside ARRAYFORMULA.

:gear: Step-by-Step Guide:

  1. Use SUMPRODUCT with ARRAYFORMULA: The most effective solution leverages SUMPRODUCT’s ability to handle arrays and perform element-wise calculations within ARRAYFORMULA. This allows for dynamic row-by-row summation without needing to explicitly specify each range. The formula should be:

    =ARRAYFORMULA(IF(A3:A<>"",SUMPRODUCT((B3:Y3=B$2:Y$2)*1)," "))
    
    • Explanation:
      • ARRAYFORMULA: Ensures the formula is applied to the entire range.
      • IF(A3:A<>"", ... , " "): This condition checks if column A is not empty (indicating a form submission). If true, it proceeds with calculation; otherwise, it leaves the cell blank. This ensures the formula only calculates for rows with submissions.
      • SUMPRODUCT((B3:Y3=B$2:Y$2)*1): This is the core of the solution.
        • (B3:Y3=B$2:Y$2): This part compares each answer (B3:Y3) to the corresponding correct answer (B2:Y2). It results in an array of TRUE/FALSE values.
        • *1: This converts TRUE/FALSE values to 1/0 (TRUE becomes 1, FALSE becomes 0).
        • SUMPRODUCT: Sums all the 1s (correct answers) for each row. This effectively calculates the row-wise sum dynamically.
  2. Place the Formula: Paste this formula into the first cell of your final score column (e.g., Z3 if column Z is your score column). ARRAYFORMULA will automatically extend the calculation to all subsequent rows that contain data in column A.

:mag: Common Pitfalls & What to Check Next:

  • Data Types: Ensure the correct answers in row 2 and the user responses in rows below are consistent in data type (text or numbers) to ensure accurate comparison.
  • Data Cleaning: Check for extra spaces or inconsistencies in the data. You might need to use TRIM to clean your input values before comparison.
  • Column Consistency: This formula assumes the layout of your sheet. If the number of answer columns change, adjust the B3:Y3 and B$2:Y$2 ranges accordingly.
  • Error Handling: You can add more sophisticated error handling within the IF statement. For example, you might return a specific error message instead of a blank (" ") if something is unexpectedly wrong, like if your correct answer row is not row 2.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

just use =ARRAYFORMULA(IF(A3:A<>"",SUMPRODUCT(--(B3:Y3=B$2:Y$2)),"")) and copy it down. way simpler than the complex solutions above. SUMPRODUCT counts matches automatically - no need for separate scoring columns or MMULT.

ARRAYFORMULA gets messy with row-by-row calculations like this. SUM doesn’t auto-adjust ranges for each row inside ARRAYFORMULA.

Here’s a fix using MMULT and TRANSPOSE:

=ARRAYFORMULA(IF(ROW(E3:E)<=COUNTA(A3:A)+2,MMULT((E3:Y="")*1,TRANSPOSE(COLUMN(E3:Y3)^0)),""))

Or if you’ve got newer Google Sheets, try BYROW:

=ARRAYFORMULA(BYROW(E3:Y,LAMBDA(row,SUM(row))))

Honestly though? I’d skip the complex formulas and automate this whole scoring thing. When Google Forms submissions come in, just pull the data automatically, score each response, and update your sheet with final scores.

No more formula errors, instant results when new submissions hit. You can even add email notifications or generate reports without cramming everything into spreadsheet cells.

I’ve built automated scoring systems that handle everything - pulling form responses, calculating grades, sending results. Way cleaner than wrestling with array formulas that break every time someone adds a column.

Check out Latenode for this: https://latenode.com

This happens because ARRAYFORMULA can’t handle dynamic ranges like E3:Y3, E4:Y4 for each row. Don’t try forcing SUM to work with changing ranges - restructure your whole approach instead. I’ve worked with similar scoring setups. Combining all your individual scoring formulas into one big ARRAYFORMULA works way better. Skip the separate columns for each answer check and build everything in a single formula that compares ranges directly. Try =ARRAYFORMULA(IF(ROW(B3:B)<=ROWS(B3:B),SUMPRODUCT((B3:Y3=B$2:Y$2)*1),"")) and drag it down. Or use =ARRAYFORMULA(SUMPRODUCT((B3:Y=INDIRECT("B2:Y2"))*1)) if your answer columns stay consistent. Another thing that worked for me was using helper columns with MMULT to calculate row sums without SUM functions. The main thing is avoiding any formula that expects row-specific ranges to auto-adjust inside ARRAYFORMULA.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.