Sub topic 8
Your First Formulas and Cell References
This chapter assumes that you can create a spreadsheet, enter data into cells, and identify rows, columns, and sheet tabs. You will use those skills to calculate totals, averages, and line-item amounts.
How formulas work
A formula is an instruction that tells Google Sheets to calculate a result. Every formula begins with an equals sign (=). You can type numbers directly, but cell references are more useful because the result changes when the referenced cells change.
For example, this formula adds two numbers:
=12+8A cell reference identifies a cell by its column letter and row number. If cell B2 contains 12 and cell C2 contains 8, you can write:
=B2+C2The formula reads the current values in B2 and C2, adds them, and displays the result. To enter a formula, select a cell, type the formula, and press Enter.
A worked example
Create this small order table:
| A | B | C | D |
|---|---|---|---|
| Item | Quantity | Unit price | Line total |
| Notebook | 3 | 4.50 | |
| Pen | 10 | 1.25 | |
| Folder | 4 | 2.00 | |
| Total |
In D2, multiply the quantity by the unit price:
=B2*C2Copy the formula from D2 down through D4. Each copied formula changes its row references automatically:
- D2 uses B2 and C2.
- D3 uses B3 and C3.
- D4 uses B4 and C4.
This behavior is called a relative reference. A relative reference changes when you copy a formula to another location.
In D5, add the line totals:
=SUM(D2:D4)SUM is a function. A function is a built-in operation that performs a calculation. The range D2:D4 means every cell from D2 through D4.
To calculate the average unit price, enter this in C5:
=AVERAGE(C2:C4)AVERAGE returns the arithmetic mean of the values in the range.
Understanding ranges and operators
A range is a group of cells. A colon separates the first and last cell in a range.
| Formula | Meaning |
|---|---|
| `=SUM(B2:B6)` | Adds all values from B2 through B6 |
| `=AVERAGE(B2:B6)` | Calculates the mean of B2 through B6 |
| `=B2*C2` | Multiplies the values in B2 and C2 |
| `=TODAY()` | Returns the current date |
Common arithmetic operators are:
+for addition-for subtraction*for multiplication/for division
Functions can also combine separate cells or ranges. For example, =SUM(B2:B6,D2:D6) adds both ranges.
What happens when data changes
Formulas recalculate when their referenced values change. If you change the quantity in B2 from 3 to 5, D2 updates because it refers to B2. The total in D5 also updates because it refers to D2:D4.
The formula remains in the cell even though the cell displays its result. Select a formula cell and look at the formula bar to inspect or edit the formula.
Common errors
A formula can produce an error when the referenced data is not suitable for the operation.
#DIV/0!appears when a formula divides by zero or by an empty cell.#VALUE!often appears when a calculation expects a number but receives text.#REF!appears when a formula refers to a cell that no longer exists, often after deleting a referenced row or column.- A wrong result can occur when a number was entered as text, such as a price with an unexpected character.
Check the cell references and the data type of each input. Do not replace a formula with a typed result unless you intend to stop the result from updating.
Exercise
In the order table, what formula should you enter in D2 to calculate the line total from the quantity in B2 and the unit price in C2?
Show answer
Enter =B2*C2. Copying it down changes the row references for the other items.