Skip to content
ArumSoft Learning
KO

    The 20 Most-Used Excel Functions · Tutorial 14 of 20

    How to Use XLOOKUP in Excel

    Find a value in one column and return the matching value from another with XLOOKUP, including a fallback for missing values, nearest matches and wildcards.

    Level
    Intermediate
    Time
    15 min read
    Updated:
    Applies to:
    Excel for Microsoft 365, Excel 2024, Excel 2021, Excel for the web
    25 isn't in A10:A12, so match_mode -1 uses the next smaller value, 10, and returns its discount: 5%.
    Example: 25 isn't in A10:A12, so match_mode -1 uses the next smaller value, 10, and returns its discount: 5%.

    What you'll learn

    • Write an XLOOKUP formula that returns a value from any column, including one to the left
    • Show your own message when a value isn't found
    • Choose a match_mode for nearest matches and wildcards
    • Use search_mode to search from the bottom of a list

    Function Playground

    Try XLOOKUP in a live sheet

    Type formulas in an Excel-style grid and watch each step of the calculation. Free, no sign-up.

    XLOOKUP finds a value in one column (or row) and returns the value in the same position from another. It does everything VLOOKUP does with fewer ways to go wrong: it matches exactly unless you ask otherwise, it can return a column to the left, and it has a built-in answer for values that aren't there.

    The syntax

    =XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
    • lookup_value is what you're looking for, such as a product name.
    • lookup_array is the single column (or row) to search.
    • return_array is the column (or row) to return from. It must have the same number of rows as lookup_array.
    • if_not_found is optional: what to show when there's no match. Leave it out and you get #N/A.
    • match_mode is optional: 0 exact match (the default), -1 exact or next smaller, 1 exact or next larger, 2 wildcard match.
    • search_mode is optional: 1 searches from first to last (the default), -1 from last to first.
    Reading an XLOOKUP formula
    =XLOOKUP(G2,B2:B7,A2:A7,"Not found")
    1. G2lookup_value: the product name to find
    2. B2:B7lookup_array: the column to search
    3. A2:A7return_array: the column to return from, here to the left of the search column
    4. "Not found"if_not_found: what to show when the name is not in B2:B7

    Find a code from a product name

    The sheet below lists six products with their codes in column A. The goal is the code for the product in G2 (Stapler), shown in G3. VLOOKUP can't do this, because the codes are to the left of the names.

    1. Click the cell for the result

      Click G3, next to the label "Code".

      ABCDEFG
      1CodeProductPriceStockLookupResult
      2P-101Notebook4.5120ProductStapler
      3P-102Pen1.2300Code
      4P-103Highlighter1.885Price
      5P-104Stapler1215Glue price
      6P-105Scissors6.540Order qty25
      7P-106Tape2.560Discount
      A product list with codes in column A and names in column B. The code for the product in G2 goes in G3.
    2. Type =XLOOKUP( and the value to find

      Type =XLOOKUP(, click G2 and type a comma.

    3. Select the column to search

      Drag over B2:B7, the product names, and type a comma.

    4. Select the column to return and press Enter

      Drag over A2:A7, the codes, and press Enter. The result is P-104.

      =XLOOKUP(G2,B2:B7,A2:A7)
      ABCDEFG
      1CodeProductPriceStockLookupResult
      2P-101Notebook4.5120ProductStapler
      3P-102Pen1.2300CodeP-104
      4P-103Highlighter1.885Price
      5P-104Stapler1215Glue price
      6P-105Scissors6.540Order qty25
      7P-106Tape2.560Discount
      XLOOKUP finds Stapler in B2:B7 (amber) and returns the code in the same row of A2:A7 (green).

    To get the price instead, point the third argument at the Price column. This returns 12:

    =XLOOKUP(G2,B2:B7,C2:C7)

    Because the search column and the return column are separate arguments, inserting a column inside the table doesn't break the formula, unlike the fixed column number in VLOOKUP.

    The return array can also be several columns wide. =XLOOKUP(G2,B2:B7,C2:D7) returns the price and the stock, 12 and 15, side by side: the result spills into the cell to the right. If that cell isn't empty, you get #SPILL! until you clear it.

    Show a message when nothing is found

    There's no Glue on the list, so a plain lookup for it returns #N/A. Add a fourth argument and XLOOKUP shows that instead:

    =XLOOKUP("Glue",B2:B7,C2:C7,"Not found")

    The result is Not found. You can use any value here: 0, an empty string "" or a cell reference. Unlike wrapping the formula in IFERROR, this replaces only the "not found" case, so other mistakes, such as ranges of different sizes, still show up as errors.

    Find the nearest match with match_mode

    Some lookups need the nearest value rather than an exact one. Rows 10 to 12 hold a discount table: orders of 1 or more get 0%, 10 or more get 5%, and 50 or more get 10%. The order quantity in G6 is 25, which isn't in the table.

    With match_mode -1, XLOOKUP returns the exact match or, if there isn't one, the next smaller value. This returns 5%, the discount for 10:

    =XLOOKUP(G6,A10:A12,B10:B12,,-1)
    ABCDEFG
    1CodeProductPriceStockLookupResult
    2P-101Notebook4.5120ProductStapler
    3P-102Pen1.2300Code
    4P-103Highlighter1.885Price
    5P-104Stapler1215Glue price
    6P-105Scissors6.540Order qty25
    7P-106Tape2.560Discount5%
    8
    9Min. qtyDiscount
    1010%
    11105%
    125010%
    25 isn't in A10:A12, so match_mode -1 uses the next smaller value, 10, and returns its discount: 5%.

    The two commas leave if_not_found empty so that -1 lands in the match_mode position. Unlike an approximate VLOOKUP, this works even if the table isn't sorted.

    match_modeFindsExample on this sheet
    0 (default)an exact match only25 returns #N/A
    -1exact, or the next smaller value25 returns 5%
    1exact, or the next larger value25 returns 10% (the row for 50)
    2a wildcard match"High*" finds Highlighter

    With match_mode 2, * stands for any number of characters and ? for exactly one. This returns 1.8, the price of Highlighter:

    =XLOOKUP("High*",B2:B7,C2:C7,"Not found",2)

    Without the 2, the asterisk is treated as a normal character and the formula shows Not found.

    Search from the bottom with search_mode

    XLOOKUP returns the first match it finds. By default it searches from the top, so in a list where the same item appears several times you get the earliest row. Set search_mode to -1 to search from the bottom up instead. In a delivery log sorted by date, with products in B2:B50 and dates in D2:D50, this returns the date of the most recent Pen delivery:

    =XLOOKUP("Pen",B2:B50,D2:D50,"None",0,-1)

    Search modes 2 and -2 run a faster binary search but need the lookup array sorted ascending or descending. On unsorted data they can return a wrong result without any error, so leave them for very large, sorted lists.

    XLOOKUP, VLOOKUP or INDEX and MATCH?

    All three find a value in a table. XLOOKUP is the most flexible; the other two work in every version of Excel.

    XLOOKUPVLOOKUPINDEX and MATCH
    Available inMicrosoft 365, Excel 2021 and laterEvery versionEvery version
    Return a column to the leftYesNoYes
    Default matchExactApproximateApproximate (write 0 in MATCH for exact)
    Column to returnA rangeA numberA range
    Insert a column inside the tableKeeps workingCan return the wrong columnKeeps working
    Value to show when nothing is foundBuilt in (fourth argument)None (wrap in IFNA)None (wrap in IFNA)
    Search from the bottomYes (search_mode -1)NoNo

    If everyone who opens the file has Excel 2021 or Microsoft 365, use XLOOKUP. If the file goes to people with older versions, use VLOOKUP or INDEX and MATCH.

    Real-world scenarios

    HR

    An employee card from one ID

    An employee list has an ID, a name, a department and an extension on every row. Type an ID in B8, and one XLOOKUP in B9 returns all of that person's details.

    ABCD
    1IDNameDepartmentExt.
    2E-101Grace KimFinance214
    3E-102Omar HaddadSales305
    4E-103Lily ChenIT118
    5E-104Jonas BergSales309
    6E-105Rosa DiazHR120
    7
    8Find IDE-103
    9ResultLily ChenIT118
    Five employees. One formula in B9 returns three columns, and the results spill into C9 and D9.
    =XLOOKUP(B8,A2:A6,B2:D6)

    The return array B2:D6 is three columns wide, so XLOOKUP returns three values for E-103: Lily Chen, IT and 118. You type the formula only in B9, and Excel fills C9 and D9. Keep those cells empty, or B9 shows #SPILL!. To return fewer columns, point the return array at just those, such as C2:D6 for the department and extension.

    Shipping

    Shipping cost by weight band

    A courier charges by weight band: up to 1 kg, up to 2 kg, up to 5 kg and up to 10 kg. Anything heavier needs a different service. Each parcel uses the first band that is at least as heavy as the parcel, which is exactly what match_mode 1 finds.

    ABCDEF
    1Up to (kg)RateOrderWeight (kg)Cost
    215.55010.85.5
    32750227
    45115033.411
    510165047.516
    650512Too heavy
    The rate table in A2:B5 and five orders. Column F finds each order's rate.

    Type this in F2 and fill it down to F6:

    =XLOOKUP(E2,$A$2:$A$5,$B$2:$B$5,"Too heavy",1)

    Order 503 weighs 3.4 kg. There's no 3.4 in the table, so match_mode 1 takes the next larger value, 5, and F4 returns 11. Order 502 weighs exactly 2 kg and matches the 2 kg band: 7. Order 505 weighs 12 kg, and nothing in the table is that large, so XLOOKUP returns the if_not_found text, Too heavy. With match_mode -1, 3.4 kg would fall into the 2 kg band, which is the wrong rule for "up to" prices.

    School

    A student's latest test score

    Test results go into a log in date order, so each student appears several times. XLOOKUP normally returns the first match, which is the oldest score. Searching from the bottom with search_mode -1 returns the newest.

    ABCDEF
    1DateStudentScoreLookupResult
    22026-09-04Mina72StudentMina
    32026-09-04Leo85Latest score84
    42026-09-11Mina78First score72
    52026-09-11Sam90
    62026-09-18Leo88
    72026-09-18Mina84
    82026-09-25Sam93
    92026-09-25Leo81
    Four weeks of test scores. F3 searches from the bottom for Mina's latest score; F4 searches from the top for her first.
    =XLOOKUP(F2,B2:B9,C2:C9,"No tests",0,-1)

    Mina appears in rows 2, 4 and 7. Searching up from row 9, the first Mina that XLOOKUP meets is in row 7, so F3 returns 84, her score from September 18. The 0 keeps the match exact, and the -1 in sixth place sets the direction. In F4, =XLOOKUP(F2,B2:B9,C2:C9) searches from the top and returns her first score, 72. A student with no tests yet would show No tests.

    Sales

    Sales for any region and quarter

    A table has regions down the side and quarters across the top. Pick a region in G2 and a quarter in G3, and an XLOOKUP inside another XLOOKUP finds the value where that row and that column cross.

    ABCDEFG
    1RegionQ1Q2Q3Q4PickLookup
    2East4,2003,9004,6005,100RegionNorth
    3West3,8004,1004,3004,700QuarterQ3
    4North2,9003,1003,5003,300Sales3,500
    5South3,3003,6003,4003,900
    Quarterly sales by region. G4 returns the value where the North row meets the Q3 column.
    =XLOOKUP(G2,A2:A5,XLOOKUP(G3,B1:E1,B2:E5))

    Work from the inside out. XLOOKUP(G3,B1:E1,B2:E5) searches the header row for Q3 and returns that whole column, D2:D5. The outer XLOOKUP then finds North in A2:A5 and returns the matching value from that column: 3,500. Change G2 or G3 and the result follows. In versions without XLOOKUP, =INDEX(B2:E5,MATCH(G2,A2:A5,0),MATCH(G3,B1:E1,0)) gives the same result.

    Mistakes that give the wrong result

    • Ranges of different sizes. =XLOOKUP(G2,B2:B7,C2:C6) returns #VALUE!, because the lookup array has six rows and the return array five. Use the same rows in both.
    • #N/A with no if_not_found. The value isn't in the lookup array, or it differs by a space or by type (the number 101 doesn't match the text "101"). Fix the data, or add a fourth argument if missing values are expected.
    • The ranges slide when you copy. Fill a lookup down a column and the arrays move with it. Lock them with F4: =XLOOKUP(H2,$B$2:$B$7,$C$2:$C$7).
    • #NAME? in an older version. The file was opened in Excel 2019 or earlier, which doesn't have XLOOKUP.
    • match_mode and search_mode mixed up. They're the fifth and sixth arguments, in that order. =XLOOKUP("Pen",B2:B50,D2:D50,"None",-1) asks for the next smaller value, not a search from the bottom. Count the commas.

    Practice

    Practice

    Look up products and discounts

    Use the sheet below. Click a highlighted cell, type a formula in the bar above the sheet and press Enter. Afterwards, try it in Excel itself:

    1. List six of your contacts with a name in column A and a phone number in column B, then a city in column C.
    2. Type a city in a cell and use XLOOKUP to return the name of someone in that city. The names are to the left.
    3. Add "No one there" as the fourth argument and type a city that isn't on the list.

    Try it0 of 4 done

    1. In G3, find the code of the product in G2. The codes are to the left of the names.
    2. In G4, find the price of the product in G2.
    3. In G5, look up the price of Glue, and show Not found if it isn't in the list.
    4. In G7, find the discount for the order quantity in G6 from the table in A10:B12.

    Click a dashed cell, type a formula in the bar and press Enter.

    ABCDEFG
    1CodeProductPriceStockLookupResult
    2P-101Notebook4.5120ProductStapler
    3P-102Pen1.2300Code
    4P-103Highlighter1.885Price
    5P-104Stapler1215Glue price
    6P-105Scissors6.540Order qty25
    7P-106Tape2.560Discount
    8
    9Min. qtyDiscount
    1010%
    11105%
    125010%

    Related

    Was this guide helpful? Spot a mistake? Send feedback · admin@arumsoft.com