How to use XLOOKUP in Microsoft Excel
The new XLOOKUP feature in the latest version of Microsoft Excel spells the end of the VLOOKUP function.
In this blog, Darren explains why you should use XLOOKUP instead of VLOOKUP, and how to use this new feature.
Hi, we are Happy
We are leading a movement to create happy, empowered and productive workplaces.
How can we help you and your people to find joy in at least 80% of your work?
One of the most exciting things about using Office 365 is the regular updates. For those of us at Happy on the Microsoft Insider programme, we get to play with these new features before they are released to the wider world.
One of these new features that has had us beside ourselves with happiness is the very exciting XLOOKUP. I have, for many years now, extoled the virtues of INDEX and MATCH over the use of VLOOKUP, but with the arrival of XLOOKUP we can finally say goodbye to the VLOOKUP.
What's wrong with a VLOOKUP?
- Defaults to an approximate match
- Only searches from the top
- When carrying out an approximate match will only return the next smaller value
- Must reference a table array, referencing unnecessary data, forcing unneeded calculations
- Can only return results from columns to the right of the lookup column
- The use of the column index number prevents column insertions or deletions in the lookup table
Most of these could be avoided by using INDEX and MATCH, but XLOOKUP fixes all of these and provides so much more.
How does XLOOKUP do better?
- Defaults to an exact match
- Will search from the bottom of an array or the top
- When carrying out an approximate match will find the closest larger or smaller value
- By referencing separate lookup and return arrays columns can be added or removed without causing errors
- This also means that the return array can be to the left of the lookup array
- By only referencing the data required the XLOOKUP will out perform an equivalent VLOOKUP
- As well as exact and approximate matches you can now use wild cards
- Will carry out a binary search on sorted data
- It also replaces the HLOOKUP
Interested? Then read on!
The anatomy of an XLOOKUP
An XLOOKUP looks like this: =XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
Let's break this down...
- Lookup_value — the lookup value, just like the VLOOKUP, is the value you are trying to match in your lookup array.
- Lookup_array — this is the column you are trying to match in, this would be the left most column in the lookup table of a VLOOKUP
- Return_array — the column or columns you require the values returned from. If you select multiple columns the new Spill feature will return a row of data from the return_array
- If_not_found – optional. No more need for the IFNA function, you can specify a value in the XLOOKUP. If you do not use this argument you will continue to receive the #NA error for value not available.
With Match_mode, we now have 4 different match options!
- 0 - exact match (default)
- -1 - exact match or next smaller item
- 1 - exact match or next larger item
- 2 - wild card character match
The wild card match could be a complete game changer! This allows you to use the classic wildcards of * and ? which means you can match parts of a string or account for misspellings.
|A lookup value of||Would match with||But not with|
|Jon Bon Jovi|
Long John Silver
This last argument is frequently dismissed by many on the web but I think this has far more potential than many realise. We have 4 options here:
- 1 - search first to last – this will find the first match starting from the first value in the lookup array
- -1 - search last to first – this will search from the last value in the lookup array. Useful if you have multiple matches but want to find the last match
- 2 - binary search (sorted in ascending order)
- -2 - binary search (sorted in descending order)
The binary search is interesting. A binary search starts at the middle value and dismisses the half of the array that the lookup value cannot be in. When looking up in very large datasets this can improve lookup speed.
XLOOKUP in action
Here is a simple example, just using the first three arguments. The account number is matched in column G:G and the last name is returned from column B:B.
In this example, the fourth argument has been used to replace the #NA error with a text string.
So is this the end for VLOOKUP?
In the short term, probably not, but as more and more organisations use Office 365 there will be less reason to use VLOOKUP and more overwhelming reasons to use XLOOKUP instead.
Why not sign up to our newsletter?
Sign up to our monthly newsletter, full of tips, tricks and news to help you to be happier and more productive at work.
Darren is one of Happy's Senior Trainers, able to train almost every IT course on our course programme. He worked for Happy for 12 years and has been an Associate Trainer since 2018.
Testimonials from happy customers
Trusted Customer2 days ago
I found the Office 365 training really useful. It consolidated my self-taught learning and showed me some new things that will make my life easier as well as doing some t...
Trusted Customer2 days ago
Found the session interactive and engaging throughout. Range of tools shared.
Helen Twigg3 days ago
Really enjoyed the Liberating Structures Online Immersion Workshop. High energy that kept you involved all day and have been able to use the learning immediately. Woul...
Ruth Gibbins3 days ago
Great facilitation, very interactive and organsied
Emma Willcox3 days ago
Great course, with lots of opportunity to practice techniques and not just learn about them. The day is packed full of content, so be ready to embrace the fast pace and t...
Judy Duff3 days ago
Happy are a creative, unique, relevant and modern-day approachers of workshop delivery and content.
Trusted Customer5 days ago
Excellent course and facilitator :) The course had good interactive sessions and well thought out content. It was made relevant to our roles and the trainer was supportiv...
Scott Haines6 days ago
I thought the training was excellent. It was really enjoyable and engaging and gave me lots of ideas to take away.
Toks Kinoshi6 days ago
An excellent session led by Henry where I learnt some new, refreshing techniques
Trusted Customer9 days ago
no documentation - forgotten the basics immediately
Janet Doran9 days ago
This webinar really delivered on making zoom interactive. Henry didn't tell us how to do it he let us experience it through his engaging style and pace, use of zoom featu...
Trusted Customer9 days ago
Fun and engsging