Sub topic 7
Reading What a Formula Does Before You Apply It
This chapter assumes you know cells, rows, columns, and ranges in Google Sheets. It also assumes you have used simple formulas such as SUM and IF, and that you can open the Gemini side panel and send a prompt. The previous chapter covered asking Gemini for formulas. This chapter covers what to do with the answer before it goes into your sheet.
Why you read before you apply
Gemini returns a formula that looks plausible. Plausible is not the same as correct. A formula can run without an error and still give the wrong number. It might point at the wrong column, include the header row, or round differently than you wanted.
Applying a formula writes it into your cells. In a sheet other people use, a wrong formula spreads quietly. Reading it first costs about a minute. Finding the error after a report has gone out costs much more.
The habit has three steps: read the formula, check your reading against Gemini's explanation, and then test it on a few rows. This chapter covers the first two. The next chapters cover aggregation formulas and testing results against your data.
Where the formula appears
When you ask for a formula in the side panel, Gemini usually shows the suggested formula in its reply. The panel also offers a way to insert it, and sometimes a preview of the result. The exact buttons and labels change between versions, so look at what your panel offers instead of relying on a fixed name.
Whatever the labels are, do not insert yet. Copy the formula text into your reading, or read it in place in the reply. Then work through the passes below.
The four-pass reading method
Take this request from the spine of this tutorial:
In column F, add a formula that shows the Amount from column D plus 10% tax, and leave the cell blank when column D is empty.Gemini might return this formula for cell F2:
=IF(D2="", "", D2*1.1)Read it in four passes.
- Where does the result go? Check the target cell. The formula is written for F2, so it belongs in F2. If your data starts in row 2 and the formula refers to row 5, something is off.
- What goes in? List every reference. Here there is one input, D2. Check that column D really holds Amount in your sheet. Do not assume it, because Gemini reads your headers and can still choose the wrong column.
- What happens, in order? Read from the inside out. The
IFtests whether D2 is empty. If it is, the result is an empty string. If not, the result is D2 multiplied by 1.1. - What happens at the edges? Ask what the formula does with an empty cell, with text, with zero, and with a negative number.
Writing the passes as a short table keeps you honest:
| Pass | Question | Answer for `=IF(D2="", "", D2*1.1)` |
|---|---|---|
| Output | Which cell? | F2 |
| Inputs | Which cells does it read? | D2 only |
| Logic | What is the order of work? | Test D2 for empty, then return blank or D2 times 1.1 |
| Edges | What breaks it? | Text in D2 gives `#VALUE!`. Zero gives 0. |
The multiplier 1.1 stands for "plus 10% tax". That matches the request. If you had asked for 8% tax and saw 1.1, the mismatch would show up in pass 3.
Reference types and range endpoints
Many wrong formulas come from the references, not the logic. Look at each reference for these points.
- Relative or absolute.
D2changes toD3when the formula is copied down.$D$2stays fixed. A tax rate stored in one cell, such as$H$1, must be absolute. If it is not, copying the formula down shifts it to an empty cell. - Start row. A range that starts at row 1 includes the header.
SUMignores text, but other functions can behave differently or return errors. - Open or closed end.
D2:Druns to the bottom of the sheet and picks up new rows.D2:D50stops at row 50, so rows added later are silently left out. - Matching sizes. Functions that take two ranges, such as
SUMIF, need ranges of the same height.B2:BandD2:D50do not match, and Sheets will report an error.
Hardcoded numbers deserve a second look. The 1.1 in the tax formula works, but a rate you might change is easier to maintain in its own cell. You can ask Gemini to do that:
Change the formula in F2 to read the tax rate from cell H1 instead of using 1.1 directly.Asking Gemini to explain a formula
You do not have to decode every function alone. Select the cell that holds a formula, or paste the formula into the panel, and ask for an explanation. Name the cell and ask for steps:
Explain the formula in F2 step by step. Say which cells it reads and what it returns when D2 is empty.Treat the explanation as a second opinion. Gemini can describe a formula incorrectly, just as it can write one incorrectly. Compare it with your own four-pass reading:
- If the two agree, you have more confidence. Two independent readings reached the same conclusion.
- If they differ, find out why before going on. Either you misread something or Gemini did.
- If the explanation is vague ("this calculates the value"), ask again with a specific question, such as what happens when the cell holds text.
A good explanation names the cells, the order of operations, and the output in the empty case. An explanation that only restates the formula in words adds nothing.
Look at the formula inside the sheet
Once a formula is in a cell, Sheets gives you tools to check it that do not depend on Gemini.
- Press
F2on a cell, or double-click it, to enter edit mode. Sheets outlines each referenced range in a matching color. You can see at a glance whether the formula points at the columns you expect. - Press
Ctrl+` (the backtick key) to show every formula in the sheet instead of its result. Press it again to go back. You can also use View, then Show, then Formulas. This helps you spot a cell where someone typed a value over a formula. - While you type a function name, Sheets shows a help box with its arguments. Use it when a function in Gemini's answer is new to you.
To trace a formula, copy its parts into a spare cell. For the tax formula, type =D2*1.1 in a scratch cell and compare it with F2. Then type =D2="" and check that it returns TRUE or FALSE as you expect. Delete the scratch cells afterward.
A worked reading: SUMIF
Here is a formula from the spine that adds up spending in one category:
=SUMIF(B2:B, "Groceries", D2:D)Run the four passes.
- Output: a single number, wherever you place it.
- Inputs: column B from row 2 down, the text "Groceries", and column D from row 2 down.
- Logic:
SUMIFtakes a range to test, a criterion, and a range to add. For every row where column B equals "Groceries", it adds that row's value from column D. - Edges: the match ignores upper and lower case, so "groceries" counts. It does not ignore extra spaces. A cell holding "Groceries " with a trailing space is not counted, and no error tells you so.
That last edge is a common source of totals that look reasonable but come up short. Check the category column for variants of the same word. The chapter on summaries returns to SUMIF, QUERY, and ARRAYFORMULA in detail. Here the point is that you can read a new formula in a minute if you ask the same four questions each time.
Common errors when reading
- Trusting the preview alone. A preview that shows one correct number does not show how the formula behaves on blank rows, text, or new rows.
- Skipping unfamiliar functions. If you cannot say what a function does, look it up in the help box or ask Gemini, and then confirm the answer in the Sheets function list.
- Ignoring overwrite risk. A formula that fills a whole column, such as one using
ARRAYFORMULA, needs empty cells below it. If the column already holds data, you get a#REF!error that says the result would overwrite existing values. Check the target column before inserting. - Reading only the first row. A formula that is right in row 2 can be wrong in row 30 if a reference is not anchored correctly. Look at the formula after it has been filled down.
Summary of the habit
Before you apply a Gemini formula, name its output cell, list its inputs, say what it does in order, and say what it does at the edges. Then ask Gemini for its own explanation and compare. When the two match and the references look right, apply the formula and move on to testing it against your data.
Exercise
Gemini suggests =IF(D2="", "", D2*1.1) for F2. Your Amount values are in column C, not D. Which pass of the four-pass method catches this, and what do you do?
Show answer
Pass 2 (inputs) catches it, because the formula reads D2 and your Amount is in C2. Do not apply the formula. Ask Gemini to change the reference with a prompt such as "Use column C for Amount instead of column D", and read the new formula again before inserting it.
Exercise
A formula =SUMIF(B2:B, "Groceries", D2:D) returns 240, but you count 300 by hand. List two causes you would check first.
Show answer
First, check column B for variants of the category, such as "Groceries " with a trailing space, which the criterion does not match. Second, check column D for amounts stored as text, which are not added. A third cause is that some rows fall outside the range, for example if the range is closed at a row above your last entry.