Keep Report Formulas Working When the Data Refreshes
Why report formulas break when imported data changes shape, and the named-range setup that keeps every total, chart and pivot pointed at the right column.
Why formulas break when the data refreshes
A report that reads imported data breaks in one of four ways, and each has a different fix:
- The range is too short.
=SUM(Deals!D2:D500)was right when you wrote it. Six months later there are 640 deals and the total quietly leaves off the newest 140. Nothing shows an error. - The cells were deleted. Some imports clear the tab by deleting its rows, or delete the tab and create a new one with the same name. Every formula that pointed there now says #REF!, because the cells it referenced are gone, even though new cells with the same address appeared a second later.
- A column moved. The app adds a field, or someone reorders the export, and what used to be column D (Amount) is now column E.
SUM(D:D)keeps working and starts adding up the wrong thing. This one is the worst, because the number looks plausible. - Someone typed into the data tab. A note in column H or a manual fix to one row is overwritten on the next refresh, or pushes an import's output sideways.
The setup that survives all four
Keep data and report on separate tabs
Let the import own one tab (Deals) completely and put every formula, chart and pivot on another (Deals report). Nobody types into the data tab. Notes and manual columns live on the report tab, matched to rows by ID. This alone fixes the fourth problem and makes the other three easier to see.
Write new data over the old cells
When the data refreshes, overwrite the values and clear anything left over below them, rather than deleting rows, columns or the tab. Formulas keep their references because the cells they point at never stop existing. If you paste exports by hand, paste over the existing block with Paste special > Values only instead of deleting the tab first.
Refer to columns by name, not by letter
There are three ways to do this in Google Sheets, from least to most robust:
- Look up the column by its header.
INDEX(Deals!A:Z, 0, MATCH("Amount", Deals!1:1, 0))returns the whole Amount column wherever it sits, so=SUM(INDEX(Deals!A:Z, 0, MATCH("Amount", Deals!1:1, 0)))survives a moved column. It's verbose, but it needs no setup. - Use a table. Convert the data range to a table (Format > Convert to table), name the table (here, Deals), and Sheets names each column after its header, so a formula reads
=SUM(Deals[Amount]). Check that the table still covers every row after an import writes more rows than it had; if not, extend the table's range. - Name each column. A named range such as
deals_amountpointing at the Amount column lets every formula say=SUM(deals_amount). Rename or move the column and the name follows it. The catch is that someone, or something, has to resize the name when the number of rows changes.
Google's rules for names: letters, numbers and underscores only, 1 to 250 characters, not starting with a number or the words true or false, and not shaped like a cell reference (A1 or R1C1).
How Cellfetch does it
Cellfetch takes the third route and does the resizing for you. Every column it writes gets a named range, and after each run it resizes every name to exactly the rows it wrote. The report tab it builds next to your data only ever uses those names.
What the names look like
Cellfetch names every column it writes and resizes each name after every run. For an import named "GitHub issues" from GitHub, the names look like this:
| Column | Named range |
|---|---|
| Number | cf_github_issues_number |
| Title | cf_github_issues_title |
| Type | cf_github_issues_type |
| State | cf_github_issues_state |
| Author | cf_github_issues_author |
| Assignee | cf_github_issues_assignee |
A report formula such as =COUNTIF(cf_github_issues_type, "Issue") keeps counting the right column after you insert or move columns or sort the rows, and after a refresh adds or removes rows.
See it on a real sheet: GitHub.
A few more rules keep things steady. The report tab is written once and then left alone: a later refresh updates the data and the small status block at the top (last refresh, rows, result, next run), never your edits. If you want a fresh copy of the report, Rebuild report makes a new tab beside the old one. And once a name is in use it never changes, so a formula you wrote six months ago still finds its column.
If you already have a tab you paste a CSV export into, with formulas pointing at it, Cellfetch can fill that tab instead of making a new one. It reads your header row, matches each column to a field from the app, and writes each refresh into your columns in your order. Columns it can't fill are never touched.
Checking a report after a refresh
Three quick checks catch most problems:
- Compare a row count on the report (
=COUNTA(deals_id)) with the number of records the app shows. - Look for #REF! with Edit > Find and replace, searching within formulas.
- Spot-check one total against the app's own screen for the same filter.
Pulling the numbers into another file? IMPORTRANGE accepts a named range as its range string, so =IMPORTRANGE("<sheet address>", "deals_amount") follows the column too; the IMPORTRANGE glossary entry covers its quirks. For the report tab itself, the dashboard guide shows the formulas behind headline numbers, breakdowns and lists, and the sales pipeline template is a finished example over a CRM's data.
Questions
Why do my formulas show #REF! after I paste in a new export?
The rows, columns or tab they pointed at were deleted and recreated. Sheets can't follow a reference to something that no longer exists, so it shows #REF!. Paste new data over the old cells (or let an import overwrite them) instead of deleting and re-adding the tab.
Why did my total stop counting new rows?
It probably uses a fixed range such as A2:A500 and the data now has 600 rows. An open-ended range such as A2:A, a named range that grows with the data, or a table reference covers every row.
Can I sort or filter the data tab?
Use a filter view, or sort a copy on the report tab with SORT or QUERY. Sorting the data tab itself is fine for formulas, but the next refresh writes rows back in the app's order, so the sort doesn't last.
What's the limit on named range names?
Google allows letters, numbers and underscores, 1 to 250 characters, not starting with a number, and not shaped like a cell reference such as A1 or R1C1.
More guides
From inside a sheet: Extensions > Add-ons > Get add-ons, search Cellfetch, Install. Then Extensions > Cellfetch > Start.