Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How can I return a room number for a person when names are not unique?

Quick answer

Do not use a name alone if it can match multiple people. Look up the room with a genuinely unique identifier, such as an assigned person ID. If you must combine fields, build a key from details that distinguish the records, then check for duplicates before using it. In Excel, XLOOKUP returns the first match it finds, so a repeated name can produce the wrong room without signaling ambiguity. [S1][S2]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I have a spreadsheet with names and room numbers. Some people share a name. Why can’t I just look up the name and return the room?

Geez

Because a name that appears more than once does not identify one person. In Excel, XLOOKUP uses an exact match by default but returns the first match it finds. If two records have the same name, a name-only lookup can return the first person’s room, even when you meant the second person. [S1]

Instead, match on a field that uniquely identifies the person in your records, such as an assigned person ID, and return the room from that same record. Check that your proposed key does not occur more than once. Excel’s duplicate-value highlighting can help flag repeated values for review. [S2]

A name can still help someone recognize a record, but it should not be treated as unique just because it looks distinctive.

Follow-up question

What if my sheet has no person ID? Could I use more than one field?

Geez

Yes. You can consider a composite key: a combination of fields intended to distinguish each record. For example, if your sheet contains Name, Department, and Building, you might create a key from all three and use it to find the room. That combination is only an example, not a guarantee of uniqueness.

Review the proposed keys for duplicates before relying on them. If two people still have the same combined values, the key remains ambiguous; add another suitable field or have the person selecting a record choose between the matching entries. Do not assume that adding a department or building automatically makes a name unique. Duplicate highlighting can help identify repeated values, but it does not decide which fields identify a person. [S2]

Follow-up question

Can you show how to lay this out in Excel, including what to change in the lookup?

Geez

Assume your data has Person ID in column A, Name in B, and Room in C. The person ID must identify one record in this sheet. Put the ID to find in E2, then use:

=XLOOKUP(E2,A:A,C:C,"No match")

This searches column A for the value in E2 and returns the corresponding value from column C. XLOOKUP returns a corresponding value from a return range and uses exact match by default. [S1] Check that the ID is unique first; if it appears in more than one row, the lookup still cannot determine which record you intended.

For a composite key, create the same key consistently for each data row and for the lookup value, then search the key column and return the room column. Verify that the key is not duplicated. Microsoft lists XLOOKUP as unavailable in Excel 2016 and 2019, so check your version if the formula is not available. [S1]

Follow-up question

What should I do when the key is still duplicated, or when the lookup finds no record?

Geez

Treat those as different problems. A duplicated key means it still does not identify one record; do not accept whichever room appears first. Review the matching rows and choose an additional distinguishing field, or have the person selecting the record clarify which entry they mean. A missing match means the lookup did not find a corresponding key; check the entered value and the source records.

For example, if two rows share the same name and department, a key made only from those fields still cannot distinguish them. You could add another appropriate field if it separates the records, then check the resulting keys again. The goal is to select the intended record, not simply to make the formula return a value. Duplicate highlighting helps with review but does not prove that a set of personal fields uniquely identifies someone. [S2]

A practical checklist

  • Prefer a person ID intended to identify one record.

  • If combining fields, choose details that can distinguish people in these records.

  • Create the proposed key consistently in the records and lookup value.

  • Review the key column for duplicates and investigate repeated keys.

  • Decide how users should handle a missing or ambiguous match.

  • Confirm your Excel version supports the lookup function you plan to use.

A few more useful answers

Does XLOOKUP tell me when a name appears more than once?

Not by itself: XLOOKUP returns the first match it finds, so a repeated name can produce a result without signaling that another match exists. Check whether the lookup key is duplicated before relying on the result. [S1][S2]

Is name plus department always a unique key?

No. It is suitable only if that combination distinguishes every relevant record. Review the proposed key for duplicates; the fields alone do not establish uniqueness. [S2]

What if my Excel version does not support XLOOKUP?

Microsoft lists XLOOKUP as unavailable in Excel 2016 and 2019. Check the functions available in your version, while keeping the same matching rule: use a verified unique key rather than a name that can repeat. [S1]

Sources

References used for this guide.

  1. [S1] XLOOKUP function — Microsoft Support
    support.microsoft.com · Checked
  2. [S2] Find and remove duplicates — Microsoft Support
    support.microsoft.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work