Excel - XMATCH Function



XMATCH Function

EXCEL XMATCH function retrieves the relative position of the data found in a array or selected cell range. It is limited to utilizing a single row or column but not compatible with multiple columns. Manually finding the position of the items in lengthy datasets is very time-consuming and tedious. The XMATCH function is exclusive to the latest version, like Excel 365 or Excel 2021.

Compatibility

This advanced Excel function is compatible with the following versions of MS-Excel −

  • Excel for Microsoft 365
  • Excel for Microsoft 365 for Mac
  • Excel for the web
  • Excel 2024
  • Excel 2024 for Mac
  • Excel 2021
  • Excel 2021 for Mac

Syntax

The syntax of the XMATCH function is as follows −

=XMATCH(lookup_value, lookup_array, [match_mode], [search_mode]) 

Arguments

You can use the following arguments with the XMATCH function −

Argument Description Required / Optional
lookup_value A cell reference points to a value that you must search for in the array. Required
look_array It specifies an array. Required
[match_model] A numeric value which can be equal to 0,-1,1,2. Optional
[search_mode] It indicates the type of search. Its value can be 1,-1, 2, -2. Optional

Types of match_model

The following types of match_model are as follows −

  • 0 An exact match(by default)
  • -1 It represents the other smallest value/Exact match.
  • 1 It specifies the other largest value/exact match.
  • 2 It specifies the wildcard like ~, ?, * match.

Types of search_mode

The following types of search_mode are as follows −

  • 1 Search begins from the first to the last.
  • -1 Search begins in reverse form.
  • 2 It conducts a binary search depending on the defined array, sorted in non-descending form.
  • -2 It conducts a binary search depending on the defined array, sorted in non-ascending form.

Points to Remember

  • If the lookup value does not reside in the array, the XMATCH function will return the #N/A error.
  • If more than one lookup value is found in the array, then the XMATCH function retrieves the relative position of the first lookup value if the fourth argument is set to 1. Otherwise, the XMATCH will return the last matching value if the fourth argument is set to -1.

Example of XMATCH Function

Practice the following example to learn the use of the XMATCH function in Excel.

Step 1 − Open a new worksheet in Excel 365 and create two tables with the corresponding entries, as depicted in the image below. Our main task is to find the relative index of Employee Daniel.

XMATCH Function

Step 2 − Enter the formula "=XMATCH(F2,Table1[Employee Name])" in the E3 cell and then press the Enter tab.

XMATCH Function

Therefore, the XMATCH function will return the value of 1, representing Daniel's employees relative position in Excel.

XMATCH Function

You can use the wildcard in the lookup value for the partial match of the string. Only two wildcards * and ? will be employed in the XMATCH function. Enter the formula "=XMATCH(F2,Table1[Employee Name],1)" in the F3 cell and hit the Enter button.

XMATCH Function

XMATCH Function

Use of INDEX Function with the XMATCH Function

To use the INDEX function with the XMATCH function in Excel, follow these steps −

Step 1 − Assume the sample dataset as shown below image −

XMATCH Function

Step 2 − Now, we must identify the relative position of the employees name. In the F2 cell, we have written the employee name "Dennis". To find its employees relative position, write the formula =XMATCH(F2,Table1[[#All],[Employee Name]]) in the F3 cell as highlighted in below image −

XMATCH Function

Step 3 − Press the "Enter" tab to extract the position number. Now, you need to determine the incentive of the Dennis employee whose relative position is 5. Write the formula =INDEX(Table1[[#All],[Incentive]],XMATCH(F2,Table1[[#All],[Employee Name]])) in the F4 cell as shown below −

XMATCH Function

Step 4 − Therefore, as highlighted in the image below, you will obtain the incentive 1000 of the Dennis in the F4 cell. Similarly, you can change the employees name in the F2 cell and retrieve its incentive as defined in the table.

XMATCH Function

Both examples provide interesting methods for enhancing Excel skills. Users must write the XMATCH formula carefully to get an accurate value; otherwise, errors may arise.

Advertisements