Pasted a New CSV and the Columns Moved? Pull Columns by Header Name, Not Position
You paste this month's sales export over last month's, and your totals are suddenly wrong. Nothing is broken in the formulas. The platform added a column, or moved one, and every formula that said "column C" now points at something else. The fix is to stop pointing at a letter and look up the column by its header text instead.
This works with plain INDEX and MATCH, so the same formulas run in Google Sheets and LibreOffice Calc, without FILTER, QUERY or XLOOKUP.
The idea in one line
MATCH finds the position of a header in row 1. INDEX uses that position as the column number. Google's INDEX help shows exactly this pattern, with MATCH("Dietary Restriction", A1:D1, 0) as the column argument.
The examples below assume:
- An Import sheet where you paste the raw CSV, headers in row 1.
- A Clean sheet that your reports read from. Row 1 holds the header names you want, row 2 holds the column number found for each, and data starts in row 3.
Checklist
☐ 1. Find each column once, in a helper row. In Clean, put the wanted header text in row 1 (for example Purchase Date and Net Total ($), two of the column names in Gumroad's sales CSV). In row 2:
=IFERROR(MATCH(A$1, Import!$A$1:$Z$1, 0), 0)
Fill it right. The 0 at the end of MATCH means exact match. Leave it out and MATCH assumes the row is sorted and can return a wrong column without any error. The IFERROR turns "not found" into 0, so you can see a missing column at a glance instead of a wall of #N/A.
☐ 2. Pull the values through that number. In Clean row 3, fill right and down:
=IF(A$2=0, "", IF(INDEX(Import!$A$1:$Z$1000, ROW()-1, A$2)="", "", INDEX(Import!$A$1:$Z$1000, ROW()-1, A$2)))
ROW()-1 makes Clean row 3 read Import row 2, the first data row. The inner IF stops empty source cells from showing as 0. Now the Clean sheet always has the same column order, whatever order the export uses.
☐ 3. Or skip the copy and total straight from the raw columns. If you only need totals, INDEX(range, 0, n) returns a whole column (Google's INDEX help: a row of 0 returns the entire column), and SUMIFS accepts it as a range:
=SUMIFS(
INDEX(Import!$A$2:$Z$1000, 0, MATCH("Net Total ($)", Import!$A$1:$Z$1, 0)),
INDEX(Import!$A$2:$Z$1000, 0, MATCH("Purchase Date", Import!$A$1:$Z$1, 0)), ">="&H1,
INDEX(Import!$A$2:$Z$1000, 0, MATCH("Purchase Date", Import!$A$1:$Z$1, 0)), "<"&EDATE(H1, 1))
With the first day of a month in H1, that sums one month's net, whichever column each header lands in. Keep all ranges the same size (rows 2 to 1000 here); Microsoft's SUMIFS page requires each criteria range to match the sum range.
☐ 4. Handle platforms that name the same field differently. Chain fallbacks, most specific first:
=IFERROR(MATCH("Net Total ($)", Import!$A$1:$Z$1, 0), IFERROR(MATCH("Net", Import!$A$1:$Z$1, 0), 0))
Add one IFERROR level per alternative name. The result is still a single column number, so nothing downstream changes.
☐ 5. When a header "isn't found" but you can see it, check the length. A trailing space is invisible. =LEN(Import!C1) returns 4 for Net and 3 for Net. Fix the header text, or add the spaced version as one more fallback. Note: some exports may also carry an invisible character before the first header; if only the first column fails, retype that header cell.
☐ 6. Check that numbers arrived as numbers. An amount stored as text ('7.00' instead of 7) can be left out of a SUMIFS total, so the total looks plausible and is still short. Compare the two counts:
=COUNT(INDEX(Import!$A$2:$Z$1000, 0, C$2))
=COUNTA(INDEX(Import!$A$2:$Z$1000, 0, C$2))
If COUNTA is higher, some cells in that column are text. Note: Google's SUMIFS help doesn't spell out how text amounts are treated, so rely on this count rather than on the total. To convert one value like $1,234.50:
=IF(ISNUMBER(C3), C3, IFERROR(VALUE(SUBSTITUTE(SUBSTITUTE(C3, ",", ""), "$", "")), 0))
Note: this works for amounts written with a comma as the thousands separator. If your export uses a comma as the decimal mark, change the substitutions to match.
☐ 7. Check dates the same way. A date column that SUMIFS can't compare silently drops every row. =ISNUMBER(A3) on a pulled date should be TRUE. If it's FALSE, the date came in as text and needs converting before any date range works.
☐ 8. Paste over the old data, not beside it. In Google Sheets, File > Import has a "Replace current sheet" option, which clears the old export so leftover rows from a longer previous file can't sneak into your totals. In other apps, clear the Import sheet before pasting.
☐ 9. Make the range wider than you need. $A$1:$Z$1 covers 26 columns. If an export grows past column Z, MATCH stops seeing the new headers. Pick a range with headroom.
What can still go wrong
| Symptom | Likely cause | Check |
|---|---|---|
| Whole Clean column blank | Header not found (helper shows 0) | Steps 1, 4, 5 |
| Total lower than the platform's | Amounts stored as text | Step 6 |
| Month total is 0 | Dates stored as text, or ranges of different heights | Steps 3, 7 |
| Old rows still counted | New export shorter than the last one | Step 8 |
| Wrong column, no error | MATCH without the 0 |
Step 1 |
Note: Google's MATCH help doesn't say whether header matching ignores upper and lower case or treats * and ? as wildcards. Typing the header exactly as it appears in the file avoids depending on either.
If you sell on several platforms
Doing this for every export, on every platform, is the repetitive part. Solo OS ($29, Google Sheets) is a finance sheet for one-person online sellers that is built on this approach. According to its product page, you paste your Gumroad, Lemon Squeezy and Payhip sales exports, and columns are matched by header name, so column order doesn't matter. It then works out net income after platform fees, affiliate commissions, PayPal/Stripe Connect fees, refunds and lost disputes, and has payout reconciliation and a monthly dashboard. It uses only common functions such as INDEX/MATCH, SUMIFS and COUNTIFS. Its listed limits include 500 rows per platform tab by default, and sample headers built from each platform's documentation rather than checked against real seller exports, so rename headers if yours differ.
Sources
- Google Docs Editors Help, INDEX (INDEX with MATCH; row 0 returns the whole column): https://support.google.com/docs/answer/3098242?hl=en
- Google Docs Editors Help, MATCH (search_type 0 for exact match): https://support.google.com/docs/answer/3093378?hl=en
- Google Docs Editors Help, Import data sets & spreadsheets ("Replace current sheet"): https://support.google.com/docs/answer/40608?hl=en
- Microsoft Support, SUMIFS function (criteria ranges the same size as the sum range): https://support.microsoft.com/en-us/office/sumifs-function-c9e748f5-7ea7-455d-9406-611cebce642b
- Gumroad Help Center, The sales analytics dashboard (sales CSV columns
Purchase Date,Net Total ($)): https://gumroad.com/help/article/74-the-analytics-dashboard
Questions this page answers:
- Retrieve Google Sheets column by header name: https://stackoverflow.com/questions/55692208/retrieve-google-sheets-column-by-header-name
- How to reference a column by header name: https://stackoverflow.com/questions/76047390/how-to-reference-a-column-by-header-name-using-data-set-named-range-in-google-s
- Sum column by referencing column header: https://webapps.stackexchange.com/questions/58893/sum-column-by-referencing-column-header
- Combine data in sheets by header name, different structures: https://stackoverflow.com/questions/77026792/combine-data-in-sheets-by-header-name-different-structures