Byte by Byte › Book 5: Games, Spreadsheets and Networks › Chapter 8: Formulas and Functions
Chapter 8: Formulas and Functions
You will learn: how to write formulas with operators and cell references, the order of operations (BODMAS), how to use the functions SUM, AVERAGE, MIN, MAX, COUNT, MEDIAN and MODE, how formulas change when you copy them (relative references), how to work out mean, median, mode and range, and how to fix common formula errors.
🌟 The Adventure
The next morning the Queen sent Tally a list of questions she wanted answered before the closing ceremony:
Which village has won the most medals? Which village has the most medal points, counting 3 for gold, 2 for silver and 1 for bronze? What is the fastest sprint time? What is the average number of points per race? And please keep every answer up to date as new races finish.
Tally read the last line three times. "Up to date," she said faintly. "Every time a race finishes. There will be forty more races today."
The status bar could add up a column, but it could not work out medal points, and it forgot its answer the moment you clicked somewhere else.
Nimo bobbed in his bubble. "Then we must write the answers into the spreadsheet," he said, "not as numbers, but as instructions. Instructions that work themselves out again whenever anything changes."
"Formulas," said Memoon.
💡 Learn With Memoon
What is a formula? A formula is an instruction in a cell that tells Excel to calculate something. Every formula starts with an equals sign (=). The cell shows the result; the Formula Bar shows the formula itself.
Operators. Excel uses these arithmetic operators:
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | Add | =7+3 | 10 |
| - | Subtract | =7-3 | 4 |
* | Multiply | =7*3 | 21 |
| / | Divide | =7/2 | 3.5 |
| ^ | Power | =2^3 | 8 (2 × 2 × 2) |
Notice that computers use * for multiply and / for divide, not × and ÷. You saw the same in Scratch.
Order of operations. Excel follows the same rules you learn in maths, called BODMAS: Brackets first, then Orders (powers), then Division and Multiplication (left to right), then Addition and Subtraction (left to right).
| Formula | Working | Result |
|---|---|---|
| =2+3*4 | 3 × 4 = 12, then 2 + 12 | 14 |
| =(2+3)*4 | 2 + 3 = 5, then 5 × 4 | 20 |
| =10-4/2 | 4 ÷ 2 = 2, then 10 − 2 | 8 |
| =2*3^2 | 3² = 9, then 2 × 9 | 18 |
When in doubt, add brackets. They never hurt and they make a formula easier to read.
Use cell references, not typed numbers. You could type =10+12+8. But if any of those numbers change, the answer will be wrong. Instead, point to the cells: =F2+F3+F4. Now the formula reads whatever is in those cells right now, and Excel recalculates the moment any of them change. This is the secret of Tally's "always up to date".
To enter a reference without typing it, type =, then click the cell; type +, then click the next. Excel colours each reference and its cell to match, which helps you check.
Functions. Adding a hundred cells with + would be painful. A function is a ready-made formula with a name. You give it values to work on, called arguments, inside brackets:
=FUNCTION(arguments) =SUM(F2:F11)
| Function | What it gives | Example |
|---|---|---|
| SUM | The total | =SUM(F2:F11) |
| AVERAGE | The mean (total ÷ how many) | =AVERAGE(F2:F11) |
| MIN | The smallest value | =MIN(E2:E5) |
| MAX | The largest value | =MAX(F2:F11) |
| COUNT | How many cells contain numbers | =COUNT(F2:F11) |
| COUNTA | How many cells are not empty (any data) | =COUNTA(D2:D11) |
| MEDIAN | The middle value when sorted | =MEDIAN(F2:F11) |
| MODE.SNGL | The most common value | =MODE.SNGL(F2:F11) |
Three quick ways to enter a function:
- Type it. Type =SU and Excel suggests SUM. Press Tab to accept, then select the range and press Enter. You don't need to type the closing bracket; Excel adds it.
- AutoSum. Click the cell under a column of numbers and click AutoSum (Σ) on the Home tab, or press Alt+=. Excel guesses the range; check it, then press Enter. The arrow beside Σ offers Average, Count, Max and Min too.
- Insert Function. Click fx beside the Formula Bar to search for any function and see what each argument means.
Statistics: describing data with numbers. In maths you learn four ways to summarise a set of numbers. Excel does each in one formula. Using the Points column from Chapter 7 (10, 12, 8, 6, 12, 8, 10, 6, 10, 12):
| Measure | Meaning | Working | Excel | Answer |
|---|---|---|---|---|
| Mean | Total ÷ how many | 94 ÷ 10 | =AVERAGE(F2:F11) | 9.4 |
| Median | Middle value when sorted | Sorted: 6, 6, 8, 8, 10, 10, 10, 12, 12, 12; middle two are 10 and 10 | =MEDIAN(F2:F11) | 10 |
| Mode | Most common value | 10 and 12 each appear 3 times | =MODE.SNGL(F2:F11) | 10 (but see below) |
| Range | Largest − smallest | 12 − 6 | =MAX(F2:F11)- MIN(F2:F11) | 6 |
Look carefully at the mode. 10 and 12 both appear three times, so this data has two modes. MODE.SNGL can only show one, so it shows the first it finds. A computer gave a correct-looking answer that tells only half the story. That is why you must understand the maths, not just press buttons. (The function MODE.MULT lists every mode.)
Which average should you use? The mean uses every value but is pulled about by one very large or very small number. The median is not affected by extreme values. The mode is best for "most popular" questions, such as the most common shoe size.
Copying formulas: relative references. This is the most powerful idea in spreadsheets. Suppose G2 holds =E2+F2. Drag its fill handle down to G3. G3 does not get =E2+F2. It gets =E3+F3. Excel moves the references by the same amount the formula moved: one row down. These are called relative references, because they are relative to where the formula is.
| Cell | Formula after copying down |
|---|---|
| G2 | =E2+F2 |
| G3 | =E3+F3 |
| G4 | =E4+F4 |
So you write a formula once for the first row, then copy it down for every other row. One formula, a thousand rows. (Sometimes you need a reference that does not move when copied. That is called an absolute reference, and you will learn it in a later book.)
Percentages. A percentage is a part of 100. To find what percentage of all medals Moonbrook won, divide its medals by the total: =E3/E7. The result is a decimal such as 0.22. Click Percent Style (%) on the Home tab to show it as 22%. Excel multiplies by 100 for display, but the cell still holds 0.22.
When formulas go wrong. Excel shows an error value instead of a result when it cannot calculate:
| Error | What it means | Typical cause |
|---|---|---|
| #DIV/0! | Dividing by zero | The cell you divide by is empty or 0 |
| #NAME? | Excel doesn't recognise a name | A misspelled function, such as =SUMM(F2:F11) |
| #VALUE! | Wrong kind of data | Doing maths with text, such as =D2+F2 when D2 is a name |
| #REF! | A reference no longer exists | You deleted a cell that a formula used |
| #### | Not an error: the column is too narrow | Widen the column |
To see every formula in a sheet at once, press Ctrl+` (the key above Tab), or use Formulas → Show Formulas. Press it again to go back. It is a great way to check your work, and a Book 4 debugging skill: isolate the problem by looking at what each cell is really doing.
💡 Memoon’s tip: After writing a formula, check it with a number you can work out in your head. If =AVERAGE(2,4) doesn't give 3, something is wrong with how you are using it.

✍️ Try It Yourself
Activity 1: BODMAS check. Open a new sheet in your Memunic Games Results workbook (click + and rename it Practice). In column A type each formula below, but first write your prediction in your notebook. Were you right every time?
- =5+5*2
- =(5+5)*2
- =20/4+1
- =20/(4+1)
- =3^2+4^2
- =100-10*3^2
Activity 2: Summary formulas. Go to the Races sheet.
- In D13 type Total points, and in F13 type =SUM(F2:F11).
- Below it, add labels in column D and formulas in column F for: Average points (AVERAGE), Median points (MEDIAN), Most points in a race (MAX), Fewest points in a race (MIN), Points range (MAX − MIN), Number of races (COUNT).
- In D20 type Fastest sprint (s) and in E20 type =MIN(E2:E5).
- Check each answer against the table in this chapter.
- Change Spike's points in Race 4 from 6 to 7. Watch which results change by themselves. Then change it back.
Activity 3: The medal table. Add a new sheet called Medals.
- Type this table, starting in A1:
| Village | Gold | Silver | Bronze |
|---|---|---|---|
| Riverbend | 4 | 3 | 5 |
| Moonbrook | 5 | 4 | 2 |
| Snowpeak | 3 | 5 | 4 |
| Pebble Hollow | 2 | 2 | 3 |
| Palace Town | 1 | 3 | 4 |
- In E1 type Total medals. In E2 type =B2+C2+D2 (or =SUM(B2:D2)). Drag the fill handle from E2 down to E6.
- In F1 type Medal points. In F2 type
=B2*3+C2*2+D2. Why are no brackets needed? Drag it down to F6. - Click F4 and look at the Formula Bar. What is the formula now? Why did it change?
- In A7 type All villages, and in B7 use SUM for the gold column. Drag B7 across to F7.
- In G1 type Share of medals. In G3 type =E3/E7 and click Percent Style. What percentage of all medals did Moonbrook win?
- Press Ctrl+` to see all your formulas, then press it again.
Activity 4: Error hunt. In the Practice sheet, make each error happen on purpose: #DIV/0!, #NAME? and #VALUE!. Write the formula that caused each one and how you would fix it.
Unplugged: The human spreadsheet. Six friends stand in a row as cells A1 to F1, each holding a card with a number. One more friend is cell G1, holding a card that says =SUM(A1:F1). G1 must call out the total. Now change one friend's card. G1 must recalculate out loud straight away. Then try G1 = MAX, MIN and AVERAGE.
🎉 Memoon Solves It
By lunchtime Tally's workbook could answer every one of the Queen's questions. The Medals sheet worked out total medals and medal points for every village with just two formulas, each written once and copied down. Moonbrook led on medal points with 25, ahead of Riverbend and Snowpeak on 23 each.
Then a runner raced in with a new result. Snowpeak had won another gold. Tally typed 4 over the 3 in the Gold column and pressed Enter.
The total changed. The medal points changed. The percentages changed. The village totals at the bottom changed. All at once, all correct.
Tally checked them anyway, twice, with a pencil. They were right.
"Forty more races," she said, and for the first time all week, she laughed.
But when the Queen came to look, she frowned slightly at the screen. "It is all very correct," she said kindly. "But it is a great many numbers. Tonight I must announce the results to all of Memunic. Can anyone see, at a glance, who is winning?"
❓ Check Your Knowledge
- What must every formula in Excel start with?
- What is the result of =4+6/2? Of =(4+6)/2? Explain using BODMAS.
- Why is =F2+F3 better than =10+12?
- What is a function? What are its arguments?
- Write the formula to find the largest number in B2:B30.
- For the data 3, 7, 7, 2, 9, 5, 2, find the mean, median, mode(s) and range by hand. Then write the Excel formula for each.
- Cell C2 holds
=A2*B2. You copy it down to C5. What formula is in C5? What is this kind of reference called? - What is the difference between COUNT and COUNTA?
- What does #NAME? usually mean? What about #DIV/0!?
- A cell holds 0.35. How will it look after you click Percent Style?
- Challenge: The Queen changes the scoring to 5 points for gold, 3 for silver and 1 for bronze. Which single cell would you edit first, and how would you update all the villages? Which village leads now?
📚 Word Bank
- Formula: an instruction in a cell, starting with =, that calculates a result.
- Operator: a symbol for a calculation: + − * / ^.
- BODMAS: the order of operations: brackets, orders, division and multiplication, addition and subtraction.
- Function: a named, ready-made formula such as SUM or AVERAGE.
- Argument: a value or range given to a function inside its brackets.
- AutoSum: the Σ button that adds a SUM (or other) function automatically.
- Mean: the total divided by how many values (AVERAGE in Excel).
- Median: the middle value when the data is sorted.
- Mode: the most common value; data can have more than one.
- Range (statistics): the largest value minus the smallest.
- Relative reference: a cell reference that changes when a formula is copied.
- Percentage: a part out of 100, shown with %.
- Error value: a code such as #DIV/0! shown when a formula cannot be calculated.
Keep learning with Byte by Byte
Explore Book 5: Games, Spreadsheets and Networks. Find the ebook, purchase details and teaching slides on MemuniCity.
Comments
Post a Comment