Sub topic 11
One Formula for the Whole Column with ARRAYFORMULA
Assume you can enter data in cells, use references such as A2, and write basic formulas with operators such as >=. This chapter shows how to apply an IF test to many rows with one formula instead of copying a formula down the column.
Why use ARRAYFORMULA?
A normal formula works on one row:
=IF(B2>=50, "Pass", "Fail")If you copy this formula down, Google Sheets changes B2 to B3, B4, and so on. ARRAYFORMULA applies the same calculation to a range of cells and returns multiple results. The results expand into the cells below the formula.
Suppose your sheet has this structure:
| A | B | C |
|---|---|---|
| Name | Score | Result |
| Lina | 72 | |
| Omar | 41 | |
| Priya | 88 |
Enter this formula in C2:
=ARRAYFORMULA(IF(A2:A="", "", IF(B2:B>=50, "Pass", "Fail")))The formula checks every row from row 2 onward. If the name is blank, it returns a blank result. Otherwise, it checks the score and returns either "Pass" or "Fail".
The result looks like this:
| Name | Score | Result |
|---|---|---|
| Lina | 72 | Pass |
| Omar | 41 | Fail |
| Priya | 88 | Pass |
How the formula works
Read the formula from the inside out:
B2:B>=50creates an array ofTRUEandFALSEvalues. Each score is compared with 50.- The inner
IFconverts each result into"Pass"or"Fail". - The outer
IFchecksA2:A="". It prevents empty rows from displaying"Fail". ARRAYFORMULAtells Sheets to perform these operations for the entire ranges.
The range A2:A means column A from row 2 to the bottom of the sheet. The range B2:B works the same way. Both ranges must cover the same rows so that each name is tested with the score from the same row.
Important rules for expanding results
The cells where the results will appear must be empty. If C4 already contains text, the formula in C2 cannot expand through that cell. Sheets reports an array expansion error.
Place the formula in the first result cell only. Do not copy it into the rows below. The formula owns the whole output range.
Avoid putting the formula in a column that it also reads. For example, a formula in B2 that reads B2:B creates a circular reference because the formula depends on its own output.
Common variations
You can return numbers instead of labels:
=ARRAYFORMULA(IF(A2:A="", "", IF(B2:B>=50, 1, 0)))You can use two conditions for each row:
=ARRAYFORMULA(IF(A2:A="", "", IF((B2:B>=50)*(C2:C>=50), "Pass", "Fail")))In this version, multiplying the two Boolean arrays acts like AND: both comparisons must be true. For an OR test, add the Boolean arrays and check whether the result is greater than zero:
=ARRAYFORMULA(IF(A2:A="", "", IF(((B2:B>=50)+(C2:C>=50))>0, "Pass", "Fail")))A frequent mistake is writing A2="" instead of A2:A="". The first expression checks only one cell, while the second checks every row in the range.
Another mistake is leaving text values unquoted. Use "Pass" rather than Pass. Also check that every opening parenthesis has a matching closing parenthesis. If your spreadsheet locale uses semicolons instead of commas, replace the argument separators accordingly.
Exercise
In a sheet where names are in A2:A and sales amounts are in B2:B, write one formula for C2 that returns "Target met" for sales of at least 1000, "Below target" for lower sales, and stays blank when the name is blank.
Show answer
=ARRAYFORMULA(IF(A2:A="", "", IF(B2:B>=1000, "Target met", "Below target")))