3 / 6 · Intro
Writing your first formulas
=5+2*3 gives 11, not 21. Microsoft's operator table says multiplication comes before addition.
Jump to the 11 practice questionsYou will learn
- Start a formula with = and use the operators
- Work out the order of operations
- Point at cells instead of typing numbers
Before this: Numbers, text and dates
1Explain
The equals sign
A formula is an instruction that the spreadsheet carries out and replaces with its answer. In this course, start every formula with =. This makes it clear that the cell should calculate rather than store ordinary text. Type =3+4 and the cell shows 7; type 3+4 without the sign and the cell holds the text 3+4. Microsoft's help puts it this way: the equal sign tells Excel that the characters that follow make up a formula. After the sign come operands, the numbers and cell references, joined by operators such as + and *.
| Operator | Meaning | Example |
|---|---|---|
| + | add | =3+3 gives 6 |
| - | subtract, or negate | =3-1 gives 2 |
| * | multiply | =3*3 gives 9 |
| / | divide | =3/3 gives 1 |
| ^ | power | =2^3 gives 8 |
| % | percent | =20% gives 0.2 |
| & | join text | ="North"&"wind" gives Northwind |
| = < > <= >= <> | compare | =3>2 gives TRUE |
2Problem
3+4 without =
You type 3+4 into a cell, with no equals sign. What is stored?
Hint
No equals sign, no calculation.
Solution
Answer: The text 3+4
Only entries that start with = are formulas.
3Problem
2^3
What does =2^3 return?
Hint
2 × 2 × 2.
Solution
Answer: 8
^ is the power operator: 2 × 2 × 2 = 8.
4Problem
10/4
What does =10/4 return?
Hint
Division can give a decimal.
Solution
Answer: 2.5
Division gives the full decimal answer: 2.5.
5Problem
Joining with &
Hint
The two words stick together.
Solution
Answer: Northwind
& joins two pieces of text into one.
6Explore
Which part is worked out first
When a formula mixes operators, Excel follows a fixed order. Microsoft lists it from first to last: negation (as in −1), percent, exponent, multiplication and division, addition and subtraction, joining text with &, and finally comparisons. Operators on the same level go from left to right. So =5+2*3 multiplies first and gives 11, while =(5+2)*3 adds first because of the brackets and gives 21. Brackets are the tool for getting the order you mean, and extra brackets never hurt.
JavaScript multiplies before it adds, like Excel. It writes the power as ** and makes you put brackets around a minus sign next to it.
console.log(5 + 2 * 3);117Problem
=5+2*3
What does =5+2*3 return?
Hint
Multiplication first.
Solution
Answer: 11
Multiplication first: 2 × 3 = 6, then 5 + 6 = 11.
8Problem
=(5+2)*3
What does =(5+2)*3 return?
Hint
Brackets first.
Solution
Answer: 21
The brackets go first: 7 × 3 = 21.
9Explain
Minus two squared
One result surprises people who know school algebra. Because negation comes before the exponent in Excel's list, =-2^2 means (−2) squared and gives 4, not −4. If you want minus two squared, write =-(2^2). It is a good example of why a formula that matters should be checked with a value you can work out in your head.
10Problem
=-2^2 in Excel
In Excel, what does =-2^2 return?
Hint
Negation comes before the exponent.
Solution
Answer: 4
Negation comes before the exponent in Excel's order, so it is (−2)² = 4.
11Explain
Point at cells instead of typing numbers
A formula such as =3.5*4 works, but it hides the numbers inside the formula. Put the price in B2 and the quantity in C2, and write =B2*C2 in D2 instead. Now the inputs are visible, and when you change the quantity in C2 the cost in D2 updates by itself. This is the main reason spreadsheets exist. You do not have to type the address: while you are writing a formula, click a cell and its address is inserted at the cursor, and dragging across cells inserts a range.
12Problem
=B2*C2+1
B2 holds 4 and C2 holds 5. What does =B2*C2+1 return?
Hint
4 × 5, then + 1.
Solution
Answer: 21
4 × 5 = 20, then + 1 = 21.
13Problem
=B2*(C2+1)
B2 holds 4 and C2 holds 5. What does =B2*(C2+1) return?
Hint
4 × 6.
Solution
Answer: 24
Brackets first: 5 + 1 = 6, then 4 × 6 = 24.
14Problem
Why point at cells
Why write =B2*C2 instead of =3.5*4?
Hint
Change an input and watch.
Solution
Answer: It updates when B2 or C2 changes
References keep the inputs visible and the answer up to date.
15Explain
Quotes, case and editing
Function and cell names are not case-sensitive, so =b2*c2 works and is shown in capitals. Text inside a formula must be in double quotes, as in ="Total: "&D4. Without the quotes, the program looks for a name called Total, finds none, and shows #NAME?. In the lab, the panel under the grid lists every cell a formula uses, in the same colour as its outline in the grid. This makes it easy to see whether a formula points where you think it does.
16Problem
#NAME? from IF
A cell holds =IF(A1>5,Yes,"No") and shows #NAME?. What is the likely cause?
Hint
Text in a formula needs double quotes.
Solution
Answer: Yes has no quote marks
Text in a formula needs double quotes; Yes alone is read as an unknown name.
17Explore
Practice in the grid
Editing works the same way in both programs. Select the cell and click into the formula bar, or double-click the cell, change the formula and press Enter to keep it or Escape to throw the change away. Typing straight into a selected cell replaces what was there, which is a common way to lose a formula by accident. If a result looks wrong, check it with numbers you can do in your head. Put 10 and 2 in the input cells, predict the answer, and see whether the formula agrees before you trust it with real figures.
Drag to turn. Scroll or pinch to zoom.
18Practice
A cost column and a total
Like =B2*C2 filled down: print price times quantity for each row, then the total of all rows.
14
12
6
32const price = [3.5, 1.2, 2];
const qty = [4, 10, 3];
let total = 0;
for (let i = 0; i < price.length; i++) {
}
console.log(total);
Hint
Each row uses its own price[i] and qty[i], like a relative reference.
A solution
const price = [3.5, 1.2, 2];
const qty = [4, 10, 3];
let total = 0;
for (let i = 0; i < price.length; i++) {
const cost = price[i] * qty[i];
console.log(cost);
total += cost;
}
console.log(total);19
Summary
- A formula starts with =.
- Order: negation, %, ^, * and /, + and −, &, comparisons. Use brackets to change it.
- Use cell references so results update when inputs change.
- Text inside a formula goes in double quotes.