ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Lookups
  3. How to Sum a Column by Its Header Name in Excel

How to Sum a Column by Its Header Name in Excel

By ExcelReady Team·Updated November 3, 2026·6 min read

The short answer

To sum a column by its header, find the column with a lookup and wrap it in SUM. In Microsoft 365 or Excel 2021, use =SUM(XLOOKUP(G2,B1:E1,B2:E6)). In any version, use =SUM(INDEX(B2:E6,0,MATCH(G2,B1:E1,0))). Change the header name in G2 and the total moves to that column.

Key takeaways

  • XLOOKUP can return a whole column: =SUM(XLOOKUP(G2,B1:E1,B2:E6)) adds the column whose header matches G2.
  • In older Excel, INDEX with a row number of 0 returns the whole column that MATCH finds.
  • The header range and the data range must start and end in the same columns, or you sum the wrong one.
  • SUMPRODUCT((B1:E1=G2)*B2:E6) also works in every version and returns 0 when no header matches.
On this page+
  1. Why sum a column by its header name?
  2. How to sum a column by header with XLOOKUP
  3. How to sum a column by header with INDEX and MATCH
  4. Use the same lookup with AVERAGE, MAX or SUMIFS
  5. The SUMPRODUCT alternative
  6. Why does the sum by header return #N/A or the wrong total?
  7. Practise it

To sum a column by its header in Excel, you let a lookup function find the column and then wrap it in SUM. Type a header name such as "Mar" in a cell, and the total switches to that column with no edits to the formula. This guide is for anyone who builds a summary or dashboard where the reader picks the month, region or product to total.

Why sum a column by its header name?#

A formula that finds its column by name keeps working when the layout changes. =SUM(D2:D6) always adds column D. If someone inserts a column or the reader wants April instead, you have to edit the formula by hand.

A header-based formula reads the column name from a cell, so one formula can answer "total for March", "total for April" and so on. It is the same idea as a two-way lookup that picks a row and a column, except that you keep every row and add them up.

All the examples use this monthly sales table in A1:E6, with the month to total in G2:

ABCDE
1StoreJanFebMarApr
2Leeds1,2009501,1001,300
3York8001,1509001,000
4Hull1,5001,2501,4001,600
5Bath700850650900
6Derby1,0001,1001,200950

How to sum a column by header with XLOOKUP#

In Microsoft 365 or Excel 2021 and later, XLOOKUP can return a whole column, so SUM around XLOOKUP does the job:

Excel formula
=SUM(XLOOKUP(G2,B1:E1,B2:E6))

Here is what each part does:

  • G2 is what to find: the header name, "Mar".
  • B1:E1 is where to look: the header row.
  • B2:E6 is what to return. It has five rows, so XLOOKUP returns all five values from the matching column.
  • SUM adds those values.

With "Mar" in G2, the result is 5,250 (1,100 + 900 + 1,400 + 650 + 1,200). Type "Feb" in G2 and it changes to 5,300. XLOOKUP looks for an exact match by default and is not case-sensitive, so "mar" works too. The XLOOKUP function guide lists the optional arguments.

How to sum a column by header with INDEX and MATCH#

INDEX and MATCH do the same job in every version of Excel. MATCH finds the column number and INDEX returns that column:

Excel formula
=SUM(INDEX(B2:E6,0,MATCH(G2,B1:E1,0)))
  1. MATCH(G2,B1:E1,0) returns 3, because "Mar" is the third header in B1:E1. The final 0 asks for an exact match. See the MATCH function guide for the other match types.
  2. INDEX(B2:E6,0,3) returns the third column of the data. The 0 as the row number is the key: it means "all rows", not one cell. The INDEX function guide explains this.
  3. SUM adds the column: 5,250 again.

This is the INDEX MATCH pattern with the row left open. If you have used INDEX MATCH MATCH for two-way lookups, you replace the row MATCH with 0. For a refresher on why MATCH returns a position, read how the MATCH function works.

Use the same lookup with AVERAGE, MAX or SUMIFS#

The lookup returns a range, so any function that accepts a range can use it. SUM is only the most common choice:

QuestionFormulaResult
Average for the month in G2 (Mar)=AVERAGE(XLOOKUP(G2,B1:E1,B2:E6))1,050
Best store result in April=MAX(INDEX(B2:E6,0,MATCH("Apr",B1:E1,0)))1,600
March total for stores that sold 1,000+ in January=SUMIFS(XLOOKUP(G2,B1:E1,B2:E6),B2:B6,">=1000")3,700

The SUMIFS version adds Leeds, Hull and Derby: 1,100 + 1,400 + 1,200 = 3,700. The criteria range (B2:B6) must have the same number of rows as the data range, or SUMIFS returns #VALUE!.

You can also flip the idea and total a row by its label. =SUM(XLOOKUP("Hull",A2:A6,B2:E6)) returns Hull's whole row and adds it: 5,750. The guide to SUM and AutoSum covers the basics of SUM itself.

The SUMPRODUCT alternative#

SUMPRODUCT can sum by header without a lookup function. It compares every header to G2 and multiplies the result by the data:

Excel formula
=SUMPRODUCT((B1:E1=G2)*B2:E6)

B1:E1=G2 gives TRUE only under "Mar". TRUE counts as 1 and FALSE as 0, so only the March column survives the multiplication. The result is 5,250.

Two differences are worth knowing:

  • No match gives 0, not #N/A. That is quieter, but it can hide a typo in G2.
  • Duplicate headers are added together. If two columns are both called "Mar", SUMPRODUCT adds both, while XLOOKUP and MATCH use only the first one.

Why does the sum by header return #N/A or the wrong total?#

Most problems come from the header text or from ranges that don't line up. Check these:

  1. #N/A: the header doesn't exist. "March" won't match "Mar", and "Mar " with a trailing space won't either. Clean the input with TRIM, or use a drop-down list for G2 so readers can only pick real headers.
  2. Dates in the header row. If B1 holds a real date shown as "Jan", the cell contains a number, not the text "Jan". Match it with a real date in G2, or use text headers.
  3. Misaligned ranges. The header range and the data range must cover the same columns. B1:E1 with C2:F6 returns the column one place to the right of the one you asked for.
  4. The label column inside the data. If the data range starts at column A, MATCH counts from A and the position is off by one. Start both ranges in column B.
  5. A blank result instead of a total. With XLOOKUP you can set a fallback: =SUM(XLOOKUP(G2,B1:E1,B2:E6,0)) returns 0 when the header is missing.

To show which header a value sits under, rather than a total, see how to return the column header for a value.

Practise it#

The formula on this page combines three skills: a lookup, a range that returns a whole column, and SUM. Practise XLOOKUP in a live spreadsheet, then practise INDEX and MATCH for files that must work in older Excel. If SUM itself is new to you, start with the SUM and AutoSum lesson. Each lesson checks your formula as soon as you press Enter.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Cell G2 holds a month name. In H2, add up the column whose header matches G2: use SUM around XLOOKUP, with B1:E1 as the headers and B2:E6 as the data.

fx
ABCDEFGHI
1
Store
Jan
Feb
Mar
Apr
Month
2
Leeds
1200
950
1100
1300
Mar
3
York
800
1150
900
1000
4
Hull
1500
1250
1400
1600
5
Bath
700
850
650
900
6
Derby
1000
1100
1200
950
7
8
9

Tip: XLOOKUP looks for G2 in the header row and returns the matching column of B2:E6. SUM adds it up.

Practise this in a lesson

LessonINDEX and MATCHCombine INDEX and MATCH to look up in any direction, including returning a column to the left of the one you search.LessonXLOOKUPLook up in any direction with XLOOKUP and show a friendly message when nothing matches.LessonSUM and AutoSumAdd up a column of numbers with SUM, then let AutoSum write the formula for you.Function guideXLOOKUPXLOOKUP explained with real examples: exact matches, looking left and custom not-found messages, plus a live exercise to try now.Function guideINDEXLearn the Excel INDEX function: return a value by row and column position, build two-way lookups with MATCH, and practice live.Function guideMATCHLearn how Excel's MATCH finds the position of a value, why the 0 matters, and how it powers INDEX/MATCH. Includes a live exercise.

Frequently asked questions

How do I sum a column based on the header name in Excel?

+

Use =SUM(XLOOKUP(G2,B1:E1,B2:E6)), where G2 holds the header name, B1:E1 is the header row and B2:E6 is the data. In older Excel, use =SUM(INDEX(B2:E6,0,MATCH(G2,B1:E1,0))).

Can XLOOKUP return a whole column?

+

Yes. When the lookup array is a row of headers and the return array has several rows, XLOOKUP returns the full matching column. You can wrap it in SUM, AVERAGE, MAX or any function that takes a range.

Why does INDEX use 0 as the row number?

+

A row number of 0 tells INDEX to return every row in the chosen column instead of a single cell. Combined with MATCH for the column number, it gives you the whole column to add up.

How do I sum a column by header and a condition?

+

Use the lookup as the sum range of SUMIFS, for example =SUMIFS(XLOOKUP(G2,B1:E1,B2:E6),B2:B6,">=1000"). The criteria range must have the same number of rows as the data.

Why does my sum by header return #N/A?

+

The header in your input cell doesn't match any header exactly. Look for extra spaces, a typo, or dates in the header row that are real dates while your input is text.

Sources

  • XLOOKUP function - Microsoft Support
  • INDEX function - Microsoft Support
  • MATCH function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. Why sum a column by its header name?
  2. How to sum a column by header with XLOOKUP
  3. How to sum a column by header with INDEX and MATCH
  4. Use the same lookup with AVERAGE, MAX or SUMIFS
  5. The SUMPRODUCT alternative
  6. Why does the sum by header return #N/A or the wrong total?
  7. Practise it

Keep reading

Lookups· 7 min read

Return the Column Header for a Value in Excel

To return the column header for a value, look across the row and bring back the header from row 1: =INDEX($B$1:$E$1,MATCH(MAX(B2:E2),B2:E2,0)) returns the header of the highest number in row 2. In Excel 2021 or Microsoft 365, =XLOOKUP(MAX(B2:E2),B2:E2,$B$1:$E$1) does the same. Replace MAX with any value to find its header.

Lookups· 6 min read

INDEX MATCH MATCH: Two-Way Lookups Explained

INDEX MATCH MATCH is a two-way lookup: =INDEX(B2:E6,MATCH(H1,A2:A6,0),MATCH(H2,B1:E1,0)). The first MATCH finds the row of the item in H1, the second finds the column of the heading in H2, and INDEX returns the value where they meet. It works in every Excel version and doesn't break when you insert columns.

Lookups· 6 min read

Two-Way Lookup in Excel (Row and Column)

A two-way lookup finds the value where a row and a column meet, like units sold for one product in one month. Use INDEX with two MATCHes: =INDEX(B2:E6,MATCH(H1,A2:A6,0),MATCH(H2,B1:E1,0)). The first MATCH finds the row, the second finds the column, and INDEX returns the cell where they cross.

More on lookups

  • Tax Bracket and Tier Lookups in Excel
  • VLOOKUP in Excel: Step-by-Step for Beginners
  • VLOOKUP From Another Workbook in Excel
  • VLOOKUP Approximate Match for Tiers and Bands
  • VLOOKUP Return Blank Instead of 0
  • VLOOKUP Column Index Number Explained
All lookups articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free