Functions Explained Archives - ExcelUser.com https://exceluser.com/category/formulas-and-functions/functions-explained/ for business users of Microsoft Excel. Tue, 28 Sep 2021 16:04:43 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.4 Excel’s XLOOKUP Function Explained https://exceluser.com/excels-xlookup-function-explained/ Tue, 28 Sep 2021 16:04:43 +0000 https://exceluser.com/?p=7465 Excel’s XLOOKUP function searches a range or an array, and returns an item corresponding to the first match it finds. If a match doesn’t exist, then XLOOKUP can return the closest (approximate) match. The XLOOKUP function has the power and flexibility of INDEX-MATCH formulas, but it’s easier to use. It’s included in Excel 365 and […]

The post Excel’s XLOOKUP Function Explained appeared first on ExcelUser.com.

]]>
Download the workbook of examples for the XLOOKUP function.
Download the example workbook.

Excel’s XLOOKUP function searches a range or an array, and returns an item corresponding to the first match it finds. If a match doesn’t exist, then XLOOKUP can return the closest (approximate) match.

The XLOOKUP function has the power and flexibility of INDEX-MATCH formulas, but it’s easier to use. It’s included in Excel 365 and in versions of Excel after Excel 2019.

Syntax for Excel’s XLOOKUP Function

=XLOOKUP( lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode] )

lookup_value Required. The value to search for. (However, if omitted, XLOOKUP searches for blank cells in the lookup_array.)
lookup_array Required. The array or range to search.
return_array Required. The array or range from which to return a value from the corresponding position of the lookup_value found in the lookup_array.
[if_not_found] Optional. Where a valid match is not found, XLOOKUP returns the if_not_found value. Its default value is #N/A.
[match_mode] Optional The match modes are:
 0 – Exact match. If none found, return an error value, as specified by the if_not_found setting. This is the default value.
-1 – Exact match. If none found, return the next smaller item.
 1 – Exact match. If none found, return the next larger item.
 2 – A wildcard match where * represents any number of characters, ? represents one character, and ~ (tilda), placed before ? or * searches for the literal value of the character.
[search_mode] Optional. The search modes are:
···  1 – Perform a search starting at the first item—the default.
··· -1 – Perform a reverse search starting at the last item.
···  2 – Perform a binary search that relies on lookup_array being sorted in ascending order. If not sorted, invalid results will be returned.
··· -2 – Perform a binary search that relies on lookup_array being sorted in descending order. If not sorted, invalid results will be returned.

Note about search_mode settings of 2 or -2: The benefit of using a binary search is that it’s a faster search method than using a sequential search, which the other search_mode settings use. However, as you’ll see in examples 14-18, using a binary search brings an extra risk. And therefore, because using Excel’s sequential search method is very fast anyway, using a binary search with XLOOKUP is seldom justified.

Examples Formulas Using Excel’s XLOOKUP Function

You can download the example workbook here.

Examples for Excel's XLOOKUP Function

=XLOOKUP( lookup_value,  lookup_array,  return_array,  [if_not_found],  [match_mode],  [search_mode] )

Examples 1 & 2: These two examples compare the INDEX-MATCH and XLOOKUP formulas. As you can see, XLOOKUP’s first two arguments are in the same order as MATCH’s first two arguments. And XLOOKUP’s last argument is the same as INDEX’s first argument.

This probably is the most frequent way you’ll use the XLOOKUP function.

Examples 3-5: These three examples search for an item that’s not in our list. In example 3, XLOOKUP returns the error value we’ve specified, which is zero. In example 4, XLOOKUP returns the next smaller value, because of the match_mode’s argument of -1. And in example 5, XLOOKUP returns the next larger value because of match_mode’s argument of 1.

XLOOKUP is Excel’s first lookup function that can return the next-smaller or next-larger value for unsorted data.

Examples 6-11: XLOOKUP has an unusual definition of “larger” or “smaller.” Normally, those terms are defined with reference to their ASCII codes. But examples 6-8 show three characters with ASCII codes that are far larger than the last letter of the alphabet. (The letter “z” has the ASCII code 122.)

And examples 9-11 show that XLOOKUP treats the first of the three codes as being smaller than “A”. It treats the second code as being larger than “O”. And example 11 treats its character as larger than any item in the list, returning the value of zero for the empty cell A9.

XLOOKUP Examples 12-18

=XLOOKUP( lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode] )

Examples 12-13: Here, we see that case doesn’t matter with XLOOKUP. Both “n” and “N” produce the same result.

Example 14: Although we specified wildcards in cell B25, XLOOKUP didn’t use those wildcards, because the match_mode was set to 1, telling Excel to return the next-higher value.

Example 15: Although this and the remaining formulas in this section use the wildcard match_mode, the value in cell B26 returns an error because its tilda (~) told Excel to look for a literal “*” character. And because there’s no such character in the list, and because the formula specifies no if_not_found value, the formula returned the default #N/A error value.

Examples 16-18: These three formulas show examples of using wildcards.

XLOOKUP examples 19-28.

=XLOOKUP( lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode] )

Examples 19-28: When XLOOKUP uses a search_mode value of 2, the lookup_array (here, the Product range) must be sorted in ascending order. When it’s not, we get unexpected results. The four zeros we see as results for XLOOKUP show that the function is returning either the top or bottom empty cell in the XLOOKUP range.

The five VLOOKUP formulas also expect a sort in ascending order, but they usually return different unexpected results.

Unfortunately, neither XLOOKUP nor VLOOKUP return an error value that alerts us when the lookup_array isn’t sorted properly.

XLOOKUP examples 29-33.

=XLOOKUP( lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode] )

Example 29: This formula searches for a non-existent value and returns an error because we didn’t specify if_not_found or match_mode settings. The formula therefore used the default values for these settings, which caused #N/A to be returned.

Examples 30-31: These formulas also search for a non-existent value. But because of the formulas’ match_mode settings, example 30 returns the next-highest value and example 31 returns the next lowest value.

Example 32: Because this formula searches a column sorted in ascending order, we can use the search-mode setting of 2. And the match_mode setting of -1 tells the formula to return the next-lower value.

Example 33: Because this formula searches a column sorted in descending order, we can use the search-mode setting of -2. And the match_mode setting of -1 tells the formula to return the next-lower value.

Note: The value of using a binary search is that it’s a faster search method than using a sequential search, which the other search_mode settings do. However, Excel’s sequential search method is so fast that the extra risk of using a binary search is seldom justified.

You can download the examples here.

Some ExcelUser Articles about Excel’s XLOOKUP Function

More Information about Excel’s XLOOKUP Function

  • XLOOKUP can return results from a closed external workbook.
  • When you search for text with the XLOOKUP function, any numbers in the lookup_array will be ignored. For example, the formula XLOOKUP(123,{5;123},{1;2}) returns 2, but  the formula XLOOKUP(“123”,{5;123},{1;2}) returns #N/A.
  • XLOOKUP is available to users of Excel 365 and any version after Excel 2019.
  • Here’s Microsoft’s help page for the XLOOKUP function.

 

The post Excel’s XLOOKUP Function Explained appeared first on ExcelUser.com.

]]>
Excel’s VLOOKUP Function Explained https://exceluser.com/excels-vlookup-function-explained/ https://exceluser.com/excels-vlookup-function-explained/#respond Tue, 28 Sep 2021 08:58:02 +0000 https://exceluser.724internetsolutions.com/?p=1571 Excel’s VLOOKUP function looks in the first column of an array and moves across the row to return the value of a cell. VLOOKUP is the least-powerful and the most-restrictive lookup function that Excel offers. To learn about a few of its problems, see Why INDEX-MATCH Is Far Better Than VLOOKUP or HLOOKUP in Excel. […]

The post Excel’s VLOOKUP Function Explained appeared first on ExcelUser.com.

]]>
Download the workbook of examples for the VLOOKUP function.
Download the example workbook.

Excel’s VLOOKUP function looks in the first column of an array and moves across the row to return the value of a cell.

VLOOKUP is the least-powerful and the most-restrictive lookup function that Excel offers. To learn about a few of its problems, see Why INDEX-MATCH Is Far Better Than VLOOKUP or HLOOKUP in Excel.

Syntax for Excel’s VLOOKUP Function

=VLOOKUP( lookup_value, table_array, col_index_num, [range_lookup] )

lookup_value Required. The value to search for in the first column of the table or range. This argument can be a value or a reference. If the value is smaller than the smallest value in the first column of the table_array argument, VLOOKUP returns the #N/A error value.
table_array Required. The range of cells that contains the data. You can use a reference to a range (for example, B2:E8), or a range name. The values in the first column of table_array are the values in which VLOOKUP searches for the lookup_value. These values can be text, numbers, or logical values. Uppercase and lowercase text are equivalent.
col_index_num Required. The column number in the table_array argument from which the matching value must be returned. A col_index_num argument of 1 returns the value in the first column in table_array; a col_index_num of 2 returns the value in the second column in table_array, and so on. Excel returns an error value if the table_array argument is less than 1 or greater than the number of columns.
range_lookup

Optional. A logical value that specifies whether you want VLOOKUP to find an exact match or an approximate match.

If range_lookup is either TRUE or is omitted, an approximate match is returned. If an exact match is not found, the next largest value that is less than lookup_value is returned.

Important: If range_lookup is either TRUE or is omitted, the values in the first column of table_array must be placed in ascending sort order; otherwise, VLOOKUP might not return the correct value.

If range_lookup is FALSE, the values in the first column of table_array do not need to be sorted. If the range_lookup argument is FALSE, VLOOKUP will find only an exact match. If there are two or more values in the first column of table_array that match the lookup_value, the first value found is used. If an exact match is not found, the error value #N/A is returned.

Example Formulas Using Excel’s VLOOKUP Function

You can download the example workbook here.

Excel's VLOOKUP function, example 1.

Excel's VLOOKUP function, example 2.

Some ExcelUser Articles about Excel’s LOOKUP Function

More Information about Excel’s VLOOKUP Function

  • VLOOKUP can return results from a closed external workbook.
  • One of the major limitations of the VLOOKUP function is that its lookup_value must be the first column of its table_array. No other Excel lookup function has this restriction.
  • Here’s the Microsoft help topic for the VLOOKUP function

You can download the example workbook here.

The post Excel’s VLOOKUP Function Explained appeared first on ExcelUser.com.

]]>
https://exceluser.com/excels-vlookup-function-explained/feed/ 0