Ravindra BagaleCourses & study guides मराठी Track your progress

4. Lookup Functions

4.6 XLOOKUP Basics and if_not_found

XLOOKUP with if_not_found with example — in 30 seconds

What: XLOOKUP looks for a value in one column and returns the matching value from another column. The 4th argument is the message when nothing is found.

Why: A new store missing from the master shows a clear message instead of #N/A, so you know to add it.

Tiny example: BLK-PUN-09 is not in the Stores sheet. XLOOKUP shows "Not in master" instead of #N/A.

First look at the data (before → after):

XLOOKUP with if_not_found with example: before and after tables, fictional FreshGo Maharashtra data

Expected result — City, with a message for unknown stores

G: Store ID P: City
BLK-PUN-01 Pune
BLK-PUN-09 Not in master
AMN-SLP-01 Solapur

About this data: Teaching sample for a fictional shop “CityBasket Retail”. Figures and names (e.g. Vikram Rao) are made up for this lesson on xlookup basics and if not found.

Before table and formula as text

Before — Stores sheet (A: Store ID … E: City Manager)

A: Store ID C: City D: Area E: City Manager
BLK-PUN-01 Pune Kothrud Ravindra Bagale
BLK-PUN-02 Pune Hinjewadi Shraddha Bagale
BLK-NSK-01 Nashik College Road Zoya
AMN-NGP-01 Nagpur Dharampeth Amir
BLK-KOP-01 Kolhapur Rajarampuri Rani
AMN-SLP-01 Solapur Murarji Peth Salman
BLK-SBN-01 Sambhaji Nagar CIDCO Raja

About this data: Demo table only — not real customer or company data. Built to practise xlookup basics and if not found.

Formula / click path

P2: =XLOOKUP(G2, Stores!$A$2:$A$8, Stores!$C$2:$C$8, "Not in master")

Do it step by step:

  1. Click P2.
  2. Type =XLOOKUP(G2, Stores!$A$2:$A$8, Stores!$C$2:$C$8, "Not in master").
  3. Press Enter and copy down.
  4. Filter column P for "Not in master".
  5. Add the missing store to the Stores sheet. The message changes to the city.

Microsoft 365 / Excel 2021+.

=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
Formula Result
=XLOOKUP(G2, Stores!$A$2:$A$8, Stores!$C$2:$C$8) City of the store
=XLOOKUP("Dharampeth", Stores!$D$2:$D$8, Stores!$A$2:$A$8) AMN-NGP-01 (left lookup, no trick needed)
=XLOOKUP("BLK-PUN-09", Stores!$A$2:$A$8, Stores!$C$2:$C$8, "Not in master") Not in master

About this data: Made-up rows so you can copy the pattern for xlookup basics and if not found. Currencies may use ₹, £, € or $.

Why XLOOKUP is better than VLOOKUP: exact match by default; separate lookup and return columns (no column counting, safe when columns move); looks left; built-in if_not_found; can search from the bottom; returns several columns at once; works vertically and horizontally.

Ravindra Bagale's Tip

In XLOOKUP, lookup_array and return_array must be the same length – if you give A2:A8 and C2:C9, you get #VALUE!. Many students take one range from row 1 and the other from row 2. Both ranges should cover the same rows. And if you are sending the file to someone else, first ask whether their Excel supports XLOOKUP.

Practice task

Replace your VLOOKUPs from 4.1 with XLOOKUP. Use if_not_found to show "Add to master" for unknown stores.

Loading practice tasks...

  1. City of a store (Easy): Find the City of BLK-NSK-01.
  2. Manager from a cell (Easy): Find the City Manager of the store in H2.
  3. Staff: team of E-1003 (Easy): Find the Team of E-1003.
  4. Not in master (Medium): Find the manager of H3. If not found show "Not in master".
  5. Area of a store (Medium): Find the Area of AMN-SLP-01.
  6. Staff: laptop of E-1002 (Medium): Find the Laptop of E-1002.
  7. Staff: unknown ID (Medium): Find the Name of E-1009. Show "Not found" if missing.
  8. Look to the left (Hard): Find the Store ID of manager "Rani".
  9. Year opened (Hard): Find the year opened of BLK-SBN-01.
  10. Staff: ID of Shahrukh (Hard): Find the Emp ID of "Shahrukh".

Quick revision cards

Three standalone cards. Each one explains the idea with its own example. Scan the QR to open this lesson.

Revision card 1: What is Xlookup Basics And If Not Found?
Card 1: What is Xlookup Basics And If Not Found? · Download PNG
Revision card 2: Tiny example — Xlookup Basics And If Not Found
Card 2: Tiny example — Xlookup Basics And If Not Found · Download PNG
Revision card 3: Checklist — Xlookup Basics And If Not Found
Card 3: Checklist — Xlookup Basics And If Not Found · Download PNG