TheLibreOffice.com

XLOOKUP in LibreOffice Calc: Exact Matches and an Older-Version Fallback

Build an exact left lookup, keep product codes intact, choose match and search modes, and check the saved workbook before sending it to an older app.

Match an ID with XLOOKUP. Two paper spreadsheet rows have the matching ID A17.

LibreOffice Calc has native XLOOKUP from version 24.8. To use it, give the formula a value to find, a row or column to search, and a matching range to return from; the return column can be on either side. I'd use exact matching for IDs and product codes, then choose an INDEX/MATCH fallback if an older app must recalculate the workbook.

The examples below start with a left lookup you can check by eye. They then cover missing values, repeated IDs, approximate matches, patterns, horizontal searches, and returning several cells. Keep the source unchanged while you establish that the first lookup works.

Check native support before adding an extension

The current XLOOKUP reference gives 24.8 as the first LibreOffice release with the function. Check Help → About LibreOffice, or LibreOffice → About LibreOffice on Mac, if the name isn't recognized. Older answers saying Calc has no XLOOKUP describe an earlier situation.

Published compatibility checks for Calc 25.8.7.3 show six cases matching their expected results, including exact lookup, a missing-value message, next-smaller matching, and reverse search. That project's first successful tested build was 24.8.7.2; it didn't test every earlier 24.8 build, so that number doesn't replace the documented 24.8 introduction.

You don't need an add-on for native XLOOKUP in a supported version. The Lox365 extension's version notes say its XLOOKUP implementation was removed in version 6 because the function had become native. A workbook using an older extension implementation needs a deliberate conversion check; installing the current extension isn't a substitute for choosing a compatible formula.

Use the formula syntax your Calc expects

These examples use English function names, semicolons between arguments, and Calc A1 references. Open Tools → Options → LibreOffice Calc → Formula, or LibreOffice → Preferences → LibreOffice Calc → Formula on Mac, to check Use English function names, formula syntax, and separators. The Formula options let you configure comma separators too; follow your settings consistently.

Use straight double quotes around text in formulas. If Calc displays a formula as ordinary text, check for a leading apostrophe or a Text-formatted formula cell, then re-enter the formula after correcting that cell's format. Don't convert the ID column to numbers while fixing a formula cell.

Calc Separators group with Function set to a semicolon, Array column to a comma and Array row to a semicolon.
The Function separator controls the character between arguments. These examples use a semicolon; check this setting before rewriting a formula. Open the controls at full size.

Build an exact left lookup

Put this small catalogue in A1:C4. Enter the IDs as text: type an apostrophe before each code, such as '0007, or format the ID cells as Text before entering them. The apostrophe marks text entry; it isn't part of the stored ID.

A: NameB: IDC: Price
Cable000712
Stand004230
Case009124
  1. Enter '0007 in E2, preserving the leading zeros as text.
  2. Enter the following formula in F2 and confirm it with Enter.
  3. Check that F2 returns Cable. Change E2 to the text ID 0042 and check for Stand.

On a narrow screen, scroll each formula sideways to see the complete line. Copy it with its punctuation and spacing unchanged.

=XLOOKUP(E2;$B$2:$B$4;$A$2:$A$4;"Not found";0)
ArgumentValue hereWhat it does
Search criterionE2The ID you want to find.
Search Array$B$2:$B$4The ID column to search.
Result Array$A$2:$A$4The name from the corresponding row.
Result if not found"Not found"The message when there is no matching ID.
Match Mode0Exact matching, also the default.
Search ModeOmittedSearch from the first item, the default mode 1.

The search and result ranges start and end on the same records. B2 maps to A2, B3 to A3, and B4 to A4. The dollar signs keep those ranges fixed when you fill the formula down; E2 remains relative so the next formula can read E3. Headers aren't included.

Exact matching is case-insensitive in XLOOKUP: Ab7 and ab7 can match. Changing Calc's global Case sensitive setting doesn't change that behavior. If letter case identifies a different item, use the EXACT helper below.

Calc catalogue with text ID 0007 in E2, Cable in selected F2, and the exact XLOOKUP formula in the Input line.
The return column can be to the left of the search column. Keep both ranges aligned to the same source rows.

Return a price or search another sheet

To return the price instead, keep the ID search range and change the result range to C2:C4:

=XLOOKUP(E2;$B$2:$B$4;$C$2:$C$4;"Not found";0)

With E2 set to text 0007, the result is 12. If the catalogue is on a sheet named Products, use the matching sheet references in both ranges:

=XLOOKUP(E2;$Products.$B$2:$B$4;$Products.$C$2:$C$4;"Not found";0)

The reference-syntax examples distinguish Calc's sheet separator from Excel A1 syntax. Selecting the ranges with the mouse helps Calc insert the sheet name correctly, especially when it contains spaces. Keep the search and result records aligned after moving the data.

Handle missing IDs without hiding a data problem

Enter a text ID that isn't in the catalogue, such as 9999. The example returns Not found; without the fourth argument, an unsuccessful lookup returns #N/A. Use a visible message while building the workbook. An empty string can make missing data disappear into an apparently finished report.

A displayed 0007 can still be the number 7 with a custom number format. It isn't proof that the source holds the text code 0007. Check the input and source type, extra spaces, and whether an import already removed meaningful zeros. Reformatting a number as Text after the zeros were lost won't recover the original identifier; correct it from the source record.

I keep an explicit missing-value message until the exceptions have been reviewed. Replacing it with zero is appropriate only when zero really means the same thing in the report. The not-found argument handles a failed match; it doesn't repair a wrongly sized range, an unrecognized function, or every error in the source.

Match mode chooses the match; search mode chooses the direction

The fifth and sixth arguments answer different questions. Use Match Mode to choose exact, approximate, or pattern matching. Use Search Mode to choose the first occurrence, the last occurrence, or a binary search. The mode definitions and restrictions are worth checking before adapting an Excel example.

Match Mode, fifth argumentMeaning
0Exact match; the default.
-1Exact match, otherwise the next smaller item.
1Exact match, otherwise the next larger item.
2Wildcard matching with *, ? and ~.
3Regular-expression matching in Calc.
Search Mode, sixth argumentMeaning
1First occurrence, searching from the start; the default.
-1First occurrence found searching from the end.
2Binary search; search array must be ascending.
-2Binary search; search array must be descending.

Binary search on an incorrectly sorted array can return invalid results. Calc also disallows combining wildcard or regular-expression Match Mode with binary Search Mode. My default is the ordinary first-to-last search: a clear result matters more than selecting a different algorithm without a reason.

Choose the first or last duplicate deliberately

For a separate check, append Cable Pro / 0007 / 18 in A5:C5, keeping the ID as text, and extend both ranges through row 5. With E2 set to 0007, these formulas give different answers:

=XLOOKUP(E2;$B$2:$B$5;$A$2:$A$5;"Not found";0;1)
=XLOOKUP(E2;$B$2:$B$5;$A$2:$A$5;"Not found";0;-1)

The first returns Cable; the second returns Cable Pro. “Last” means position in the range, not newest date. XLOOKUP selects a match; it doesn't return every record with that ID or add their prices. Decide whether duplicates are valid before choosing reverse search to conceal them.

Use approximate matching for a numeric band

On a separate sheet named Bands, put this table in A1:B4. Enter the minimum quantities as numbers.

Minimum quantityBand
0Starter
100Standard
500Volume

Enter 250 in Bands.E2. This formula picks the band whose minimum has been reached:

=XLOOKUP(E2;$A$2:$A$4;$B$2:$B$4;"Out of range";-1;1)

The result is Standard, from the next smaller threshold, 100. An exact 500 returns Volume. A value below the smallest threshold returns the not-found message. Changing the fifth argument to 1 makes 250 select the next larger threshold, 500, and return Volume instead. That is a different rule, not an interchangeable way to write the same lookup.

Keep the table in a clear order and move each band label with its threshold when sorting. The example uses ordinary Search Mode 1, so don't confuse its matching rule with the sorted-array requirement of binary search.

Use wildcards only when you want a pattern

Return to the original three-record catalogue. This searches the Name column for a name beginning with Ca and returns its ID:

=XLOOKUP("Ca*";$A$2:$A$4;$B$2:$B$4;"Not found";2)

The result is 0007 from Cable, the first match; Case also fits the pattern. The star matches multiple characters and the question mark matches a single character. Match Mode 2 is what enables the pattern. With the default exact mode, inserting a star into the search text doesn't request wildcard matching.

The resolved wildcard question shows this specific trap when adapting an Excel tutorial. For a product code that contains a literal star, keep exact mode instead of turning its characters into a pattern. Use Calc's regular-expression mode 3 only when you intend that syntax, and check it separately before exchanging the formula with another app.

Horizontal lookup uses a row instead of a column

If H1:J1 contains Jan, Feb, Mar and H2:J2 contains 120, 180, 150, the following returns 180:

=XLOOKUP("Feb";$H$1:$J$1;$H$2:$J$2;"Not found";0)

The search array stays one-dimensional: one row here, or one column in the catalogue. A two-dimensional table isn't the search array for a single XLOOKUP. Use the particular row or column containing your keys and align the result range with those keys.

Return several cells from the matched row

For the original A1:C4 catalogue, XLOOKUP can return the whole matching record rather than just a name. Set E2 to text 0007. Select an empty three-cell destination such as F8:H8 and enter:

=XLOOKUP(E2;$B$2:$B$4;$A$2:$C$4;"Not found";0)

Confirm it as an array formula with Ctrl+Shift+Enter on Windows/Linux or Command+Shift+Enter on Mac. The expected cells are Cable | 0007 | 12. The array-formula instructions also describe the Function Wizard's Array checkbox and explain why typing curly braces manually doesn't create an array formula.

A multi-cell return is several fields from one matched record. It isn't all records with the same ID. Select the entire result array when you need to edit or remove it; individual cells in the result are protected as part of that array.

Match an ID and a location together

An ID alone isn't enough when the same item has stock in several locations. I'd make the two checks visible in a helper column: you can inspect which row matches before asking XLOOKUP to return its stock.

On a separate sheet, put this table in A1:C4, keeping the IDs as text. Put Match in D1, the text ID '0007 in F2 and West in G2.

A: LocationB: IDC: Stock
East000712
West00075
East00428

Enter this formula in D2 and fill it down through D4:

=IF(AND(B2=$F$2;A2=$G$2);1;0)

AND requires both comparisons to be true; IF then returns 1 for a matching row and 0 otherwise. D2:D4 should show 0, 1, 0. The dollar signs keep every helper formula pointed at the same two input cells.

In H2, look for that 1 and return stock from the same row:

=XLOOKUP(1;$D$2:$D$4;$C$2:$C$4;"Not found";0)

The expected result is 5. Change G2 to East and check for 12; change it to North and check for Not found. The helper provides the single search column XLOOKUP expects, while the stock range stays aligned with it. If more than one helper cell is 1, the default search returns the first matching row; it doesn't add their stock. Decide how to handle those duplicate records before using the result.

For repeated lookups, give G2 a location dropdown after checking the examples above. Select G2, open Data → Validity → Criteria, choose Cell range under Allow and set Source to $A$2:$A$4. Enable Show selection list; Sort entries ascending removes duplicate entries, leaving East and West. Select West and check that H2 returns 5. The dropdown helps avoid mistyped locations; it does not change the lookup formula or its case behavior.

Keep letter case significant in an ID

If your IDs contain letters and their case matters, replace the helper formula in D2 with this version and fill it down through D4:

=IF(AND(EXACT(B2;$F$2);A2=$G$2);1;0)

EXACT compares text with case sensitivity, so =EXACT("Ab7";"ab7") returns FALSE, while identical text returns TRUE. The location still uses the ordinary equality comparison. Keep the XLOOKUP in H2 unchanged: it now searches the flags produced by the stricter ID check.

Use INDEX/MATCH when an older app must recalculate

For the original scalar left lookup, use this alternative:

=INDEX($A$2:$A$4;MATCH(E2;$B$2:$B$4;0))

MATCH with type 0 and INDEX work together: MATCH finds the position of the ID, then INDEX returns that position from the names. With text 0007, the result is Cable. A missing ID returns #N/A. This replaces the ordinary one-result lookup, not every XLOOKUP mode or multi-cell result. If the key is already in the first column and the answer is to its right, the VLOOKUP guide gives another older-version option; it cannot replace the left lookup above.

MATCH can interpret search text through Calc's wildcard or regular-expression settings. If IDs contain characters such as * or ?, check LibreOffice Calc → Calculate in Options or Preferences and validate literal-code cases. Don't assume an exact-type MATCH formula makes every pattern character literal.

Microsoft states that Excel 2016 and Excel 2019 don't support XLOOKUP. Use the fallback when those recipients need an editable, recalculating workbook. Keep an ODS master, save a separate XLSX copy, and reopen that exact copy in the intended app. Change the lookup key and inspect the recalculated result, missing-ID behavior, and any array output. The Calc and Excel handoff guide covers the wider workbook check.

When the formula fails or returns the wrong item

On a narrow screen, scroll this table sideways to match each symptom with its first check and the corrective action.

SymptomCheck firstAction
#NAME? or an unrecognized XLOOKUPApp version, function language and imported formulaConfirm native support and the expected function name. Use a checked INDEX/MATCH formula for older apps.
Not found for an ID you can seeStored code and input, not just displayCompare text/number types, meaningful zeros, spaces and the actual source range.
Correct-looking but wrong recordRange alignment and duplicatesMatch the same record boundaries; choose first or last deliberately.
A wildcard pattern finds nothingFifth argumentUse Match Mode 2 and ordinary Search Mode 1.
Numeric band is too high or lowMeaning of the thresholdsChoose next smaller -1 or next larger 1 from the business rule.
Results fail after selecting binary searchSource sort orderReturn to ordinary search or establish the required ascending/descending order with labels aligned.
Only one field appears from a multi-cell returnArray entry and destinationSelect the output range and confirm the formula as an array.
Formula appears as text or won't parseFormula cell format, quotes and separatorsCorrect the formula cell, use straight quotes, follow configured syntax and re-enter.

Before filling a whole column or sending the workbook, check one known ID, one absent ID, and any duplicate rule your source needs. Then change the key in the saved return copy. Those checks establish whether the formula is following the rule you intended.

Text Import preview with ID column set to Text, leading-zero IDs 0007 and 0042, and Date set to Date (DMY).
When the source is CSV, import identifiers such as 0007 as Text. A display format cannot restore zeros already discarded during import. Open the controls at full size.

Filed under Calc