Byte by Byte › Book 7: Networks, Programming and Machine Learning › Chapter 13: Advanced Spreadsheets
Chapter 13: Advanced Spreadsheets
You will learn: relative, absolute and mixed cell references, named ranges, percentages and percentage change, nested IF and IFS with AND and OR, conditional functions (COUNTIF, COUNTIFS, SUMIF, SUMIFS, AVERAGEIF), looking up data with XLOOKUP and VLOOKUP, data validation, conditional formatting with formulas, PivotTables and PivotCharts, choosing charts, Goal Seek, common error values, and how spreadsheets can mislead.
🔎 The Case
Tally spread her printouts across the desk and tapped them with her pencil. "Every forward of the clips, from every village, by every kind of account, on Monday and Tuesday."
"Monday was before the explainer and the app," said Memoon. "Tuesday was after."
"Exactly. So we can measure what happened, instead of guessing." Tally pushed her visor up. "In the Games last year you used Excel for medal tables: SUM, AVERAGE, IF, charts. Good. Today you'll need the grown-up tools. Questions like: what percentage did forwarding fall in each village? Which kind of account still does most of the forwarding? And if we want forwards down to almost nothing, how many more people need the app?"
Vega looked at the eighteen-thousand-row printout. "You want us to type all that?"
"Certainly not," said Tally. "The hub summarised it for us. Twenty rows. And twenty well-organised rows, with the right formulas, can tell you more than eighteen thousand messy ones."
💡 The Concepts
Remember from Book 5. A spreadsheet is a grid of cells, each named by its column letter and row number (B3). A formula starts with = and can use functions such as =SUM(D2:D21) . When you copy a formula with AutoFill (dragging the fill handle at the bottom-right corner of a cell), its cell references change to match their new position. This chapter builds on all of that.
Relative, absolute and mixed references. A normal reference such as D2 is a relative reference: when the formula is copied one row down, it becomes D3 . Usually that is what you want. But sometimes a formula must keep pointing at one fixed cell, such as a total. Then you need an absolute reference, written with dollar signs: $D$23 . The dollar sign locks the part after it.
| Reference | Column when copied sideways | Row when copied down | Type |
|---|---|---|---|
D2 | Changes | Changes | Relative |
$D$23 | Fixed | Fixed | Absolute |
$A2 | Fixed | Changes | Mixed (column locked) |
B$1 | Changes | Fixed | Mixed (row locked) |
To find each row's share of the total forwards, the formula in E2 is =D2/$D$23 . Copied down to E3, it becomes =D3/$D$23 : the first part moved, the total did not. Without the dollar signs, E3 would wrongly say =D3/D24 , an empty cell, and show the error #DIV/0! .
Shortcut: while typing a formula, click in a reference and press F4. Each press cycles through D23 , $D$23 , D$23 and $D23 .
Named ranges. Instead of $D$23 , you can give a cell or range a name. Select D23, click in the Name Box (left of the formula bar), type Total and press Enter. Now =D2/Total works anywhere in the workbook, and is far easier to read. Names are always absolute.
Percentages. A percentage is a fraction of 100. In Excel, calculate the fraction ( =D2/$D$23 gives 0.2007...) and then click Home → % (Percent Style) to show it as 20%. Use Increase Decimal to show 20.1%. Never multiply by 100 and use Percent Style, or you get 2007%.
Percentage change compares a new value with an old one:
percentage change = (new − old) ÷ old
In Excel: =(C2-B2)/B2 , formatted as a percentage. A negative answer is a decrease. Moonbrook went from 2,790 forwards to 590: (590 − 2,790) ÷ 2,790 = −78.9%.
Nested IF and IFS. In Book 5 you used IF with two outcomes. To choose between three or more, put an IF inside another IF . This is a nested IF:
=IF(D2>=1000, "High", IF(D2>=300, "Medium", "Low"))
Excel checks the conditions in order, like if / elif / else in Python (Book 6). The IFS function does the same more neatly: =IFS(D2>=1000, "High", D2>=300, "Medium", TRUE, "Low") . The final TRUE acts like else .
AND, OR and NOT combine conditions, as in Python: =IF(AND(A2="Mon", D2>500), "Busy Monday", "") and =IF(OR(B2="Moonbrook", B2="Riverbend"), "River valley", "Hills") .
Conditional functions. These functions count, add or average only the rows that meet conditions.
| Function | Example | Meaning |
|---|---|---|
COUNTIF(range, criteria) | =COUNTIF(D2:D21, ">1000") | How many forward counts are over 1,000 |
COUNTIFS(range1, criteria1, range2, criteria2, ...) | =COUNTIFS(A2:A21, "Mon", D2:D21, ">500") | How many Monday rows have over 500 forwards |
SUMIF(range, criteria, sum_range) | =SUMIF(C2:C21, "New", D2:D21) | Total forwards by new accounts |
SUMIFS(sum_range, range1, criteria1, ...) | =SUMIFS(D2:D21, A2:A21, "Mon", C2:C21, "New") | Total forwards by new accounts on Monday |
AVERAGEIF(range, criteria, average_range) | =AVERAGEIF(C2:C21, "New", D2:D21) | Average forwards per row for new accounts |
Conditions with comparisons go in quotes: ">1000" , "<>Snowpeak" (not equal to). Watch the argument order: SUMIF puts the range to add last, but SUMIFS puts it first.
Looking up data. A lookup finds a value in one column and returns the matching value from another, like looking up a key in a Python dictionary (Chapter 7).
XLOOKUP is the modern lookup function in Microsoft 365 and Excel for the web:
=XLOOKUP(B2, $H$2:$H$6, $I$2:$I$6, "none")
This means: look for the village in B2 down the list H2:H6; return the value in the same position from I2:I6; if not found, show "none". The ranges are absolute so the formula can be copied down.
Older versions of Excel use VLOOKUP (vertical lookup): =VLOOKUP(B2, $H$2:$I$6, 2, FALSE) . It looks in the first column of the table H2:I6 and returns the value from column number 2 of that table. The FALSE means "exact match only"; forgetting it is one of the most common spreadsheet mistakes. XLOOKUP is easier and safer, but you will see VLOOKUP in many existing spreadsheets.
Data validation. Data validation controls what can be typed into a cell, catching mistakes before they happen (you did this in code in Book 6 and Chapter 10). Select the cells, then Data → Data Validation:
- List: a drop-down of allowed values, such as
Mon,TueorNew,Old. - Whole number or Decimal between a minimum and maximum, such as forwards from 0 to 100000.
- Date within a range.
- Input Message shows a hint when the cell is selected; Error Alert shows a message when the rule is broken.
Conditional formatting with formulas. In Book 5 you highlighted cells above a value. With Home → Conditional Formatting → New Rule → Use a formula to determine which cells to format, you can format whole rows using a formula. Select A2:D21 and enter =$C2="New" with a pale orange fill: every row where column C says New turns orange. The $ locks column C, so every cell in the row checks column C, while the row number changes.
Other useful formats: Data Bars (a bar inside each cell showing its size), Color Scales (a colour gradient from low to high) and Icon Sets (arrows or traffic lights).
Sorting and filtering, again. Data → Sort can sort by several levels: for example by Day, then by Forwards from largest to smallest. Freeze Panes (View → Freeze Panes → Freeze Top Row) keeps headings visible while you scroll through long data.
PivotTables. A PivotTable summarises a large table in seconds, without writing any formulas. You choose which fields to group by and what to calculate, and Excel builds the summary. You can rearrange ("pivot") it by dragging fields.
To make one: click anywhere in the data, then Insert → PivotTable → OK (a new sheet is created). In the PivotTable Fields pane, drag fields into four areas:
| Area | What it does | In our example |
|---|---|---|
| Rows | One row per value | Village |
| Columns | One column per value | Day |
| Values | What to calculate (Sum, Count, Average) | Sum of Forwards |
| Filters | Show only some data | Account (New or Old) |
The result:
| Sum of Forwards | Mon | Tue | Grand Total |
|---|---|---|---|
| Moonbrook | 2,790 | 590 | 3,380 |
| Palace Town | 2,310 | 500 | 2,810 |
| Pebble Hollow | 1,260 | 350 | 1,610 |
| Riverbend | 1,790 | 440 | 2,230 |
| Snowpeak | 550 | 130 | 680 |
| Grand Total | 8,700 | 2,010 | 10,710 |
If the source data changes, right-click the PivotTable and choose Refresh. A PivotChart (PivotTable Analyze → PivotChart) draws a chart that changes whenever the PivotTable does.
Choosing the right chart. You learned chart types in Books 5 and 6. The rule is to choose the chart that answers the question.
| Question | Chart |
|---|---|
| How do categories compare? | Column or bar chart |
| How did something change over time? | Line chart |
| What share of the whole does each part make? (a few parts only) | Pie or doughnut chart |
| Are two numbers related? | Scatter chart (Book 6) |
| Two measures with different scales together | Combo chart (columns plus a line on a second axis) |
Give every chart a clear title and axis titles, with units.
What-if analysis and Goal Seek. A spreadsheet model lets you ask "what if?" by changing an input and watching the results update. Goal Seek works backwards: you choose the result you want, and Excel finds the input that produces it.
Tally's simple model predicts daily forwards as =5000-8*B26 , where B26 is the number of villagers using the app. To find how many users would bring forwards down to 1,000: Data → What-If Analysis → Goal Seek; Set cell: the formula cell; To value: 1000; By changing cell: B26. Excel answers 500. (A model is only as good as its formula: real life is rarely this simple, as Chapter 14 will show.)
Error values. When a formula cannot work, Excel shows an error value. Knowing what each means saves time.
| Error | Meaning | Common cause |
|---|---|---|
#DIV/0! | Division by zero | Dividing by an empty cell, often a missing $ |
#N/A | Value not available | A lookup could not find a match |
#NAME? | Excel does not recognise a name | A spelling mistake in a function name, or text without quotes |
#VALUE! | Wrong type of value | Doing arithmetic on text |
#REF! | Invalid cell reference | A cell the formula used has been deleted |
#### | Not an error | The column is too narrow: widen it |
=IFERROR(formula, "message") shows a friendly message instead of an error.
How spreadsheets can mislead. Numbers feel objective, but the way they are presented can mislead, deliberately or by accident (Book 5).
- A chart whose vertical axis does not start at zero can make a small difference look huge.
- Percentages without the real numbers can mislead: "forwards in Snowpeak rose 100%" sounds alarming, but might mean 2 forwards instead of 1.
- Averages hide extremes: one huge value can pull the average far from what is typical (that is why the median exists).
- Correlation is not causation (Book 6): forwards fell after the explainer, but something else might also have changed that day.
Real World: Government open-data portals such as data.gov.in publish thousands of datasets, from rainfall and crop production to school enrolment, as downloadable spreadsheets. Journalists, researchers and students analyse them with exactly the tools in this chapter.
Career Spotlight: Data analyst. Data analysts turn raw data into answers for businesses, hospitals, governments and sports teams. Spreadsheets, PivotTables and charts are their everyday tools, along with Python (Book 8) and databases (Book 6).

🛠️ Build It
Create a new Excel workbook and save it as Clip Forwards in Documents.
Activity 1: Enter the data. In the first sheet (rename it Forwards), type these headings in A1:D1 and the twenty rows below them (A2:D21). Use Data Validation lists for columns A ( Mon,Tue ) and C ( New,Old ) before you start typing.
| Day | Village | Account | Forwards |
|---|---|---|---|
| Mon | Moonbrook | New | 2150 |
| Mon | Moonbrook | Old | 640 |
| Mon | Riverbend | New | 1380 |
| Mon | Riverbend | Old | 410 |
| Mon | Pebble Hollow | New | 960 |
| Mon | Pebble Hollow | Old | 300 |
| Mon | Palace Town | New | 1720 |
| Mon | Palace Town | Old | 590 |
| Mon | Snowpeak | New | 430 |
| Mon | Snowpeak | Old | 120 |
| Tue | Moonbrook | New | 380 |
| Tue | Moonbrook | Old | 210 |
| Tue | Riverbend | New | 290 |
| Tue | Riverbend | Old | 150 |
| Tue | Pebble Hollow | New | 240 |
| Tue | Pebble Hollow | Old | 110 |
| Tue | Palace Town | New | 310 |
| Tue | Palace Town | Old | 190 |
| Tue | Snowpeak | New | 90 |
| Tue | Snowpeak | Old | 40 |
("New" means an account less than a month old.) Freeze the top row.
Activity 2: Absolute references.
- In C23 type
Totaland in D23 type=SUM(D2:D21). You should get 10710.
- In E1 type
Share. In E2 type=D2/$D$23, press Enter, and format it as a percentage with one decimal place. You should see 20.1%. - AutoFill E2 down to E21. Click E3 and read its formula in the formula bar. Which part changed, and which did not?
- Now try it the wrong way: in F2 type
=D2/D23and fill it down. What appears, and why? - Delete column F. Then name D23
Totalwith the Name Box, and change E2 to=D2/Total. Fill down again.
Activity 3: Levels with nested IF. In F1 type Level . In F2 type =IF(D2>=1000, "High", IF(D2>=300, "Medium", "Low")) and fill down. How many rows are High? Then add a conditional formatting rule to A2:F21 using the formula =$C2="New" with a light orange fill.
Activity 4: Conditional functions. In H1 to H6 type these labels, and in I1 to I6 the formulas. Check your answers.
| Label (H) | Formula (I) | Answer |
|---|---|---|
| Rows over 1000 | =COUNTIF(D2:D21, ">1000") | 3 |
| Busy Monday rows | =COUNTIFS(A2:A21, "Mon", D2:D21, ">500") | 6 |
| New-account forwards | =SUMIF(C2:C21, "New", D2:D21) | 7950 |
| New on Monday | =SUMIFS(D2:D21, A2:A21, "Mon", C2:C21, "New") | 6640 |
| Average per New row | =AVERAGEIF(C2:C21, "New", D2:D21) | 795 |
| New share of all | =I3/Total | 74.2% |
Activity 5: Lookup. In K1:L6 type a small table of Truth Desk volunteers: K1 Village , L1 Volunteer ; then Moonbrook / Luna, Riverbend / Ribbit, Pebble Hollow / Spike, Palace Town / Pip, Snowpeak / Vega. In G1 type Volunteer and in G2 type =XLOOKUP(B2, $K$2:$K$6, $L$2:$L$6, "none") . Fill down. (If your Excel has no XLOOKUP, use =VLOOKUP(B2, $K$2:$L$6, 2, FALSE) .) Change "Snowpeak" in K6 to "Snow Peak". What happens in column G? Change it back.
Activity 6: PivotTable and PivotChart.
- Click any cell in A1:D21, then Insert → PivotTable → OK.
- Drag Village to Rows, Day to Columns, and Forwards to Values. Check your table matches the one in The Concepts.
- Drag Account to Filters, then choose only New. What were the Monday and Tuesday totals for new accounts?
- Click inside the PivotTable, then PivotTable Analyze → PivotChart → Clustered Column → OK. Add the title Forwards of the clips, before and after.
- Next to the PivotTable, calculate each village's percentage change with
=(C5- B5)/B5(adjust the cells to match where your Mon and Tue numbers are). Which village fell the most?
Activity 7: Mixed references. On a new sheet, type 1 to 10 in B1:K1 and 1 to 10 in A2:A11. In B2 type =$A2*B$1 . Fill it right to K2, then fill B2:K2 down to row 11. You have built a complete multiplication table with one formula. Explain why each $ is where it is.
Activity 8: Goal Seek. In the Forwards sheet, type App users in A26 and 0 in B26; type Predicted forwards in A27 and =5000-8*B26 in B27. Use Data → What-If Analysis → Goal Seek to find how many app users would bring predicted forwards down to 1,000, and then to 200. What answers do you get? Why might a real result be different?
Unplugged: Human PivotTable. Give each person a card showing one row of the data (day, village, account, forwards). Ask everyone to stand in groups by village. A "calculator" adds up each group. Then regroup by day, then by account type. Each regrouping is a pivot. How long did it take compared with Excel?
✅ Case Closed
Tally's PivotTable told the story at a glance. Forwards of the clips had fallen from 8,700 on Monday to 2,010 on Tuesday: a fall of 76.9%. Every village had fallen by more than 70%. Moonbrook, where most forwards had begun, had fallen the most: 78.9%.
"The explainer and the app worked," said Pip, delighted.
"Something worked," said Tally. "Correlation is not causation. But it's a very good sign."
Then she switched the filter to New accounts, and the room went quiet again. On Monday, new accounts had made 76.3% of all forwards. On Tuesday, even after the echo birds had been fixed, they still made 65.2%.
"Someone is still making accounts," said Vega. "Not with birds this time. By hand, or some other way. And they're using them to push the clips."
And there was something worse. While they had been working, the Mirror had published three new clips. Every day, there would be more. Each one had to be checked by hand, frame by frame, by people who were already exhausted.
"We can't keep up," said Memoon. "We need something that can look at a clip and tell us if it's likely to be fake. Something that learns."
Nimo floated up from the corner, where he had been quietly listening all evening. "Then it's time," he said, "to build an AI. Properly. From the beginning."
❓ Test Yourself
- What is the difference between a relative and an absolute cell reference? Write an example of each.
- The formula in E2 is
=D2/$D$23. What will it be when copied to E7? And to F2? - What do
$A2andB$1lock? What kind of reference are they? - What does pressing F4 do while editing a formula?
- Last year 400 students used the library; this year 520 did. Calculate the percentage change. Write the Excel formula if last year is in B2 and this year in C2.
- Write a nested IF that shows "A" for marks of 90 or more, "B" for 75 to 89, and "C" for anything lower, for a mark in B2.
- Write formulas to: (a) count the cells in C2:C50 equal to "Riverbend", (b) add D2:D50 only where C2:C50 is "Riverbend", (c) add D2:D50 where C is "Riverbend" and A is "Mon".
- What does XLOOKUP do? What does the fourth argument, such as "none", do?
- What do the four areas of a PivotTable do?
- What is Goal Seek used for?
- What do these errors mean:
#DIV/0!,#N/A,#NAME?? - Give two ways a chart or a percentage could mislead a reader.
- Challenge: Using your class's real (anonymous) data, such as hours of sleep, minutes of screen time and travel time to school, build a workbook with data
validation, a PivotTable, a chart answering one clear question, and a short written conclusion that says what the data does and does not prove.
📚 Key Terms
- Relative reference: a cell reference that changes when the formula is copied, such as
D2. - Absolute reference: a cell reference that stays fixed when copied, such as
$D$23. - Mixed reference: a reference with only the column or only the row locked, such as
$A2. - Named range: a name given to a cell or range, used in formulas.
- Percentage change: (new − old) ÷ old, shown as a percentage.
- Nested IF: an IF function inside another IF function.
- IFS: a function that tests several conditions in order.
- COUNTIF / COUNTIFS: count cells that meet one / several conditions.
- SUMIF / SUMIFS: add cells that meet one / several conditions.
- AVERAGEIF: average the cells that meet a condition.
- Lookup: finding a value and returning a matching value from another column.
- XLOOKUP / VLOOKUP: the modern / older lookup functions.
- Data validation: rules that control what can be entered in a cell.
- Conditional formatting: formatting that changes depending on cell values.
- PivotTable: an interactive summary of a table, grouped by chosen fields.
- PivotChart: a chart linked to a PivotTable.
- Combo chart: a chart that combines two chart types, often with two axes.
- What-if analysis: changing inputs to see how results change.
- Goal Seek: finding the input that gives a chosen result.
- Error value: a code such as
#DIV/0!showing why a formula failed. - IFERROR: a function that replaces an error with a chosen value.
Keep learning with Byte by Byte
Explore Book 7: Networks, Programming and Machine Learning. Find the ebook, purchase details and teaching slides on MemuniCity.
Comments
Post a Comment