Function Problems

Fix Excel Lookup Results on the Wrong Row with a Unique Key

Tauseeq MagsiTauseeq Magsi Dec 2, 2026 869 views

Question details

Match lookup results to the correct vendor and invoice rows without changing the original export layout.

Fix Excel Lookup Results on the Wrong Row
Product
Microsoft Excel
Device & OS
not provided
Scenario
An exported dataset contains repeated vendors, invoices, or date ranges, and lookup results need to be aligned with the correct records.
Observed behavior
Some lookup results are correct, but others appear on the wrong row when records share the fields used by the formula.
Before you start

Identify the fields that distinguish each record in both datasets, such as vendor, invoice number, start date, and end date. Check that corresponding fields use consistent text and date formats, and use working sheets or a Power Query import to preserve the original export layout.

Solution 1Recommended

Match records using a composite helper key

Use a key combining vendor, invoice, and dates when a date-only lookup matches more than one record.

1
Create working sheets

Copy the relevant target and exported data to separate working sheets, leaving the original export unchanged. For the example below, name the source working sheet Source_Work.

2
Build matching keys

On both working sheets, arrange vendor in column B, invoice number in C, start date in D, and end date in E. In F2, enter =B2&"|"&C2&"|"&TEXT(D2,"yyyy-mm-dd")&"|"&TEXT(E2,"yyyy-mm-dd"), then fill the formula down. Adjust the references to match your data.

3
Look up the result

On the target working sheet, enter =XLOOKUP(F2,Source_Work!$F$2:$F$1000,Source_Work!$G$2:$G$1000,"Not found",0) in the result column and fill it down. Replace column G with the source column containing the value you need.

4
Check duplicate keys

Use Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values on the source key column. If different records share a key, add another identifying field to the key on both sheets and repeat the lookup.

Match records using a composite helper key
Identical keys need more information: XLOOKUP returns the first match. If records are identical across all available identifying fields but require different results, another reliable identifier or matching rule is needed.
Try WPS Spreadsheet

Match Invoice Records with a Helper Key in WPS Spreadsheet

Use a composite key and an exact-match INDEX and MATCH formula in WPS Spreadsheet to align values with vendor and invoice records while keeping the original export intact.

  1. 1. Open the workbook: Open the exported workbook in WPS Spreadsheet and copy the source and target data to separate working sheets.
  2. 2. Create helper keys: On both working sheets, add a helper column that joins the same identifying fields. For example, with vendor in B, invoice in C, and dates in D and E, enter =B2&"|"&C2&"|"&TEXT(D2,"yyyy-mm-dd")&"|"&TEXT(E2,"yyyy-mm-dd") in F2 and fill down.
  3. 3. Match the result: On the target sheet, enter =IFERROR(INDEX(Source_Work!$G$2:$G$1000,MATCH(F2,Source_Work!$F$2:$F$1000,0)),"Not found") in the result column. Adjust the sheet name and ranges, then fill down.
  4. 4. Review the matches: Check the helper keys and results for duplicates or missing matches. Add another identifying field to both keys if different source records share the same key.
Match records using vendor, invoice, and date fields togetherKeep the original export layout unchanged on a separate sheetOpen and edit Microsoft Excel XLSX and XLS filesUse familiar spreadsheet formulas and controls
microsoft office alternative - wps office

Frequently Asked Questions

Why does my lookup return a value from another invoice?

A lookup based only on start and end dates can match multiple invoices. Include the vendor and invoice number in a composite key, then use an exact-match XLOOKUP or INDEX and MATCH.

What if the composite key still appears more than once?

Check the source key column for duplicates using Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values. Add a reliable distinguishing field to both keys; otherwise, a lookup may return the first matching record rather than the intended one.

Can I fix the lookup without changing the exported sheet?

Yes. Copy the data to working sheets and add helper columns there, or use Data > Get Data to import the files into Power Query and load the matched results to a new sheet.

Why does a matching record show as not found?

Check for extra spaces, different text formats, or dates stored as text. Clean corresponding fields in both datasets and ensure the helper-key formulas use the same field order and date format.