How to Use OFFSET and XMATCH Functions Together in Excel

Published on

We often use the OFFSET and XMATCH functions together to match a value in one column and return a corresponding value from another column in Excel. Additionally, we can use XMATCH to match multiple values and extract the intermediate values from another column.

When dealing with values between two points, the values to match may either both be distinct, or one value may be distinct while the other is repeated. Let’s explore these scenarios with examples of using OFFSET and XMATCH in Excel.

Example 1: OFFSET and XMATCH Basic Use in Excel

Imagine you have student names in column A and their total marks in column B. The range is A2:B4:

The following formula will return the marks of “Mike”:

=OFFSET(B2, XMATCH("Mike", A2:A4)-1, 0, 1, 1)
Using XMATCH function to offset rows in Excel

In this formula, OFFSET is used to return the value from a specified number of rows and columns away from a starting cell.

Syntax: OFFSET(reference, rows, cols, [height], [width])

The function XMATCH("Mike", A2:A4) finds the relative position of “Mike” in the range A2:A4, which is 2. Since Excel’s OFFSET uses zero-based indexing, we subtract 1 to get the correct row offset (rows).

The starting cell reference B2 (reference) is where the offset begins. If you change the reference to A2, the formula will return a value from column A instead.

This demonstrates the basic use of the OFFSET and XMATCH combination in Excel.

Example 2: OFFSET and XMATCH to Extract Values Between Two Distinct Values

In this example, the data includes student names as headers in column A, with their subject-wise marks listed below. Column B contains the corresponding marks. The range is A1:B13:

To extract all marks for “Mike” based on the names “Mike” and “Rose” as boundaries, use the following formula:

=OFFSET(B2, XMATCH("Mike", A2:A13), 0, XMATCH("Rose", A2:A13) - XMATCH("Mike", A2:A13) - 1, 1)
Using OFFSET and XMATCH functions to extract values between two distinct values in Excel

Here, XMATCH("Mike", A2:A13) locates the starting position of “Mike” (rows) in column A. Similarly, XMATCH("Rose", A2:A13) locates the starting position of “Rose”. The difference between these positions, minus 1, determines the height (number of rows) of the range to extract.

OFFSET starts at B2 (reference), moves down by the rows returned by XMATCH("Mike", A2:A13), and retrieves values from column B corresponding to the range between “Mike” and “Rose”.

This formula is useful for extracting intermediate values based on two distinct boundaries.

Example 3: OFFSET and XMATCH to Extract Values Between One Distinct Value and Another Duplicate Value

Sometimes, you may need to retrieve all marks for a student without specifying the name of the next student. For example, if you want all marks for “Rose” until the last subject “Chemistry,” use this formula:

=LET(
   xm_, XMATCH("Rose", A2:A13), 
   xmo_1, OFFSET(A2, xm_, 0, 10), 
   xm__, XMATCH("Chemistry", xmo_1), 
   OFFSET(B2, xm_, 0, xm__, 1)
)
Using OFFSET and XMATCH functions to extract values between one distinct value and another duplicate value in Excel

This formula uses LET to define intermediate variables and simplify the calculation.

The variable xm_ stores the position of “Rose” in column A, while xmo_1 offsets from A2 by this position and retrieves 10 rows (an arbitrary number larger than the expected rows). Then, xm__ calculates the position of “Chemistry” within this range.

Finally, OFFSET(B2, xm_, 0, xm__, 1) retrieves the marks for “Rose” up to “Chemistry.”

This approach is particularly useful when the second boundary value appears multiple times in the data.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Merge Duplicate Rows and Keep Latest Values in Excel

Here’s a dynamic array formula approach to merge duplicate rows and keep the latest...

Cycle Highlights in Google Sheets – Rotate Highlights Daily

Want to cycle highlights in Google Sheets every day? Whether you're rotating a meal...

Filter Rows Containing Multiple Selected Values in Google Sheets

This tutorial explains how to filter rows in a column containing multiple selected drop-down...

Two-Way Lookup with XLOOKUP in Google Sheets

When you need to look up one search key vertically and another horizontally, you...

More like this

Merge Duplicate Rows and Keep Latest Values in Excel

Here’s a dynamic array formula approach to merge duplicate rows and keep the latest...

XLOOKUP with Match Mode 3 in Excel (Regex Match)

XLOOKUP becomes more powerful in Excel with the new match mode 3, which enables...

Hierarchical Number Sorting in Excel with Modern Functions

A hierarchical numbering system in Excel allows you to organize data into a clear,...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.