XMATCH

Short answer

Find which column holds this month

XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])
Excel version
2021+
Also searched as
match replacement, find column number for month, position of value in list, last match position, dynamic period offset, reverse search

What it returns

XMATCH returns the position of lookup_value inside lookup_array, counted from 1. Look for March in a row of twelve month headers starting at January and you get 3.

Exact match is the default. That is the difference from MATCH that matters most. MATCH with its third argument left out runs an approximate match that assumes sorted data, and on unsorted data it returns a wrong position with no error. XMATCH left to its defaults either finds the exact value or returns #N/A.

Pass an array as lookup_value and XMATCH spills one position per item. That turns a list of header names into a list of column numbers, which is how you feed CHOOSECOLS or INDEX without hard-coding.

Arguments that matter

ArgumentRequiredWhat it does
lookup_valueYesWhat you are looking for. A selected month in $C$3, a scenario name, a header label.
lookup_arrayYesOne row or one column to search. Fcst!$D$5:$O$5 for a row of month headers.
match_modeNo0 exact (default). -1 exact or next smaller. 1 exact or next larger. 2 wildcard.
search_modeNo1 first to last (default). -1 last to first. 2 and -2 are binary search on data sorted ascending or descending.

Two of these change how you build.

search_mode of -1 finds the last match. In a monthly grid where actuals stop partway through the year, XMATCH(TRUE, rng<>0, 0, -1) returns the position of the last month with a number in it. No array formula, no LOOKUP(2,1/…) trick.

match_mode of -1 handles thresholds. A covenant step-down table with test dates as lower bounds, or a rate card keyed on volume tiers. The table does not need to be sorted.

In a financial model

XMATCH is the pointer. It rarely sits on a report as a number. It sits inside INDEX, CHOOSECOLS or TAKE, telling them which column or row to read.

The common jobs:

  • A period selector. The reader picks a month in one input cell, and every month-to-date column on the summary tab follows it.
  • A scenario switch. A cell holds “Base”, “Upside” or “Downside”, and XMATCH finds which block of the assumptions table to read.
  • A year-to-date range. INDEX with an XMATCH inside returns a range end, so SUM runs from January to the selected month.
  • The last actual month. Search last to first for the most recent non-zero value and drive the forecast start from it.
  • A membership test. ISNUMBER(XMATCH(x, list)) returns TRUE when the item is in the list. HAS says the same thing more plainly, once it leaves Insiders preview.

All of these depend on the header row holding real values that compare cleanly. Month headers should be real dates, per date headers are real dates, laid out left to right per time runs left to right, always.

Worked example

A forecast block on tab Fcst. Month-end dates run across Fcst!$D$5:$O$5 (Jan-26 to Dec-26). Line items run down column B from row 6 to row 40. On the summary tab, the reader picks a month in $C$3, entered as 30-Apr-2026.

The column for the selected month:

=XMATCH($C$3, Fcst!$D$5:$O$5)
Fcst!D5E5F5G5H5Result
Jan-26Feb-26Mar-26Apr-26May-264

Pull the whole month as a spilled column, one value per line item:

=INDEX(Fcst!$D$6:$O$40, 0, XMATCH($C$3, Fcst!$D$5:$O$5))

The 0 for the row argument tells INDEX to return every row of that column. Year to date for the line in row 6:

=SUM(Fcst!$D6:INDEX(Fcst!$D6:$O6, XMATCH($C$3, Fcst!$D$5:$O$5)))

INDEX returns a reference here, so the colon builds a range from January to April. Change $C$3 to July and the sum runs seven months.

The last month with revenue booked, from an actuals tab Act where revenue sits in row 12 and future months are blank:

=XMATCH(TRUE, Act!$D$12:$O$12<>0, 0, -1)

If actuals run through September, this returns 9.

Old way vs new way

The MATCH version of the period pointer:

=MATCH($C$3, Fcst!$D$5:$O$5, 0)

The XMATCH version:

=XMATCH($C$3, Fcst!$D$5:$O$5)

Same answer when you remember the 0. Forget it in MATCH and you get an approximate match that returns a plausible wrong column. XMATCH has no such trap, and the last-to-first search replaces a whole class of array tricks.

Where it breaks

XMATCH returns #N/A for a month that is clearly in the header. The selector holds a first-of-month date and the headers hold month-ends, or one side carries a time component. Exact match compares serial numbers, and 30-Apr is not 1-Apr. Fix: pick one convention for the whole model and enforce it with data validation on the selector, or drive the selector from the header row itself with a dropdown list.

XMATCH returns #N/A and the headers look like dates. The headers are text that reads “Apr-26”, typed or pasted from an export. A real date never matches text. Fix: rebuild the header row as real dates, =EOMONTH(D5,1) across, formatted to show mmm-yy.

A converted MATCH now returns the wrong tier. MATCH’s match_type of 1 means next smaller. XMATCH’s match_mode of 1 means next larger. The signs run opposite. Fix: when you replace MATCH(x, rng, 1), write XMATCH(x, rng, -1), and test one value that falls between two thresholds.

Wildcards stopped matching. MATCH with 0 honours * and ?. XMATCH with its default exact mode treats them as literal characters. Fix: pass 2 as match_mode when you want wildcard matching.

The position is right but INDEX reads the wrong column. XMATCH counts from the start of lookup_array. If the header range starts in column D and the INDEX range starts in column C, every answer is shifted by one. Fix: make the header range and the data range start in the same column, and check one period by hand.

Binary search returns a wrong position. search_mode 2 or -2 assumes sorted data and returns garbage on anything else, with no error. Fix: leave search_mode at the default unless the list is sorted by construction and large enough to matter.

XMATCH returns #NAME?. The file is open in Excel 2019 or earlier. Fix: use MATCH(x, rng, 0) if the model has to travel, and always write the 0.

Related functions

  • XLOOKUP. Returns the value instead of the position. Reach for it when you want the attribute, not a pointer for another function.
  • CHOOSECOLS. Takes the positions XMATCH returns and pulls those columns out of an extract. The pair replaces hard-coded column numbers.
  • TAKE. With XMATCH supplying the count, returns the first n months of a grid for a year-to-date block.
  • INDEX and MATCH. The legacy pair. Use them when the file must open in Excel 2019, and never leave MATCH’s third argument blank.
  • The play on date headers are real dates is what keeps a period selector matching every month.

All functions