The ultimate VLOOKUP trick – Multi-condition Lookup

Share

Facebook
Twitter
LinkedIn

This is a guest post by Sohail Anwar.

Let’s not bore you with an intro. You are about to learn a VLOOKUP trick that Lucifer himself would not want you to know. It’s so absurdly powerful that it was developed in a lab and had to be tested on Rocky’s arch nemesis Ivan Drago.

VLOOKUP Trick for Multi-condition lookups

Presenting the Multiple criteria VLOOKUP!

…boring…pass, we’ve seen it.

Oh, have you? Not like this you haven’t. This will change the way you work with Excel.

Let me start with an easy example. Here’s some data and we would love to know what Bb and Dd is.

Example data - Multi criteria lookup in Excel

Easy. Let’s put a helper column in that concatenates the two inputs and do a basic VLOOKUP.

Multi-condition lookup using helper columns

Puh-lease. How boring.

Bye Bye Helper Column, it was nice while it lasted.

With a dash of CHOOSE and sprinkling of Array formulas, we’re about to change the game:

=VLOOKUP($E2,CHOOSE({1,2},$A$2:$A$7&$B$2:$B$7,$C$2:$C$7),2,0) and press Ctrl + Shift + Enter

Multi-conditional VLOOKUP with CHOOSE - Explained

Without getting into too many details, using the Array creates a makeshift virtual helper column. You don’t have to understand Array formulas to make them work for you. I will lay out the simple structure that you can replicate

VLOOKUP(lookup value, CHOOSE({1,2,...N},Column1 & Column 2 &…& Column N, Result Column),2,0)

Where the lookup value is either something pre-concatenated (like Bb or Dd above) or you are using multiple criteria that you concatenate when entering the lookup value. The CHOOSE structure is easy. Always {1,2} then concatenate (with &) as many columns as you want (that the lookup values will need to look in) and the VLOOKUP’s column number is always 2. Let’s explore another example:

Multi-condition vlookup - another example

Let’s say we want to look up the Savings Produced for a Director of Grade D who started in 2014. That’s 3 lookup criteria. Let’s follow the structure.

=VLOOKUP(A13&A14&A15,CHOOSE({1,2},A2:A10&B2:B10&C2:C10,D2:D10),2,0) and press Ctrl + Shift + Enter

The two key things to note is that our lookup value is a concatenation of the criteria, in this case I have put the criteria in A13, A14 and A15 (hence A13&A14&A15 is our lookup value). Secondly, in the CHOOSE formula, the ranges in the middle part (A2:A10&B2:B10&C2:C10) have to be concatenated in the same order that the lookup value was concatenated. So we concatenated:

Start Year & Grade & Role

In both the lookup value and lookup columns within the CHOOSE.

I stumbled on this many years ago at work and it is the easiest way to do multiple criteria lookups. Play around and add more criteria…but that’s just the beginning!

When I get that feeling, it’s like Textual Healing

So how can we take this concept and make it even more useful?

First, let me share my story of pain and anguish.

Often when dealing with volumes of text data I make numerous helper columns to deal with the multitude of ways I am presented with names. Anyone who’s reconciled HR data to Finance data for example can appreciate that pain. Finance write their names First Name (column 1) Surname (column 2), then HR provide a spread with Last Name, Surname (column 1), then all of a sudden the Project team join in the fun with First Name, Surname (column 1)! Arrghh!

So I am now left to deal with this chaos via numerous text formulas involving SEARCH, LEFT, RIGHT, MID, LEN and MYSANITY (okay perhaps that last one is my own UDF, my volatile UDF). So, maybe it’s not that bad, but when you’ve been doing it for as long as I have, it gets tedious and you begin to search for efficiency. So, one day like the rebellious closing scene from Dead Poet’s society, I stood on my desk and declared ‘Oh Captain, My Captain’ as I refused to create another ‘helper’ column.

No more inconsistent data - using multi-condition lookups to handle inconsistent data

After my colleagues talked me down from the table and reassured me (“There there Sohail, I don’t mind inserting new columns for you occasionally”…”Sure you don’t John, sure you don’t”), I went about finding a less ‘helpful’ way. Would you believe, our new friend the multiple criteria lookup was the answer.

You see, not only can our criteria be cell references but also extra characters! Let’s say we have First Name(Column A), Surname (Column B) and Unique Reference (Column C). Someone gives us a spreadsheet with the names in either a First Name + Surname or Surname, First Name format. We can look this up by including the extra characters in our lookup columns within the CHOOSE.

Handling inconsistent data with multi-condition array lookup formulas

Look closely at the middle of the CHOOSE since that’s where the magic is. Download the workbook to see the example in action.

Multi-condition array lookup formula in action

We have pretty much instructed the two columns we are looking up to join up in a specific way. First we want them to join up with a space in between. Then the second formula has asked them to join up Surname, comma and space in between, then finally the First Name. So as far as Excel is concerned we have created two virtual helper columns that look like this:

How virtual helper columns work - Multi-condition lookup formula

This makes it straightforward for us to look up John Johnson or Johnson, John in them.

There are virtually no bounds to how you can use this Multiple Criteria VLOOKUP. It made my life tremendously easy and I’m sure it makes yours easier too. Do me a favor and let me know in the comments some of the crazy ways you are applying it.

And then if you haven’t already grabbed a copy of Chandoo’s VLOOKUP book I cannot recommend it enough as the ultimate resource in VLOOKUP mastery

Download Example Workbook

Click here to download the example workbook prepared by Sohail. Play with it to learn more.

Added by Chandoo

Thank you Sohail

Thank you Sohail for writing this very useful, incredibly fun tutorial. I am sure our readers will enjoy it as much as I do. Thanks.

If you like this, please say thanks to Sohail.

Related discussion on Multi-conditional lookups

As you can guess, this is not the first time we talked about using multiple conditions in VLOOKUP. Check out below articles for more ideas & tips:

 

About the author: Sohail Anwar is a Londoner who has spent over 10,000 hours applying Excel in his professional life and earns well over 6 figures as a result. Now he’s on a mission to teach professionals how to massively increase their earnings by learning and applying Excel like never before. Find out more about Sohail on Earn With Excel or  LinkedIn

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

23 Responses to “Shift Calendar Template – FREE Download”

  1. Alvin says:

    Hi Chandoo,

    your recent postings include only Excel 2007 templates. Unfortunately the company I work at still runs Excel 2003. Is it possible to get your awesome files in other excel version as well?

    Thanks so much for your great excel stuff!

  2. Stelios Tserkezis says:

    Is it possible to do this for shifts with hours instead of days? To organise a three shift day?

    Thanks in advance,

    Stelios

  3. MASTHAN says:

    In my organization there are 45 employees i need split then into three shifts ex:A shift:14,B shift:14,C shift:14 and week off:3 kindly help me on this.

  4. Hui... says:

    @Masthan

    You need to understand what rules your company has for the various shifts / roster combinations

  5. Georges Lacombe says:

    Chandoo, I once did a shift control spreadsheet for my team. I put one person in each line, the columns were the days. I put a shift code in each cell indicating in which shift that person should work, or if the person were out that day. I have two codes for being out. One is for vacations and one is to compensate days worked in weekends. This way I was able to count how many persons I have in each shift, how many were on vacations and how many were out compensating (that's the term we use here) weekend worked hours.
    Later I included the possibility of a person be in two lines one for normal hours other for overtime. This is mainly used for planning purposes. If you would like I can send you an example. The only problem of this spreadsheet is that we don't have a person view, only this consolidated view.

    • Chuck Vaughan says:

      Hi George, I would like to have a copy of your spreadsheet if you can share it.
       
      Thanks in advance, Chuck   

  6. Idan says:

    Hi Chandoo,

    Where is the code located ? is it VBA ? If so , how do you hide it ? Or it is .NET ?

    Thx

  7. Hui... says:

    @Idan
    .
    No VBA or code, it is all done with Mirrors.
    Only Joking,
    .
    But there is no VBA or code,
    It is all done with Named Formulas and Lookups.
    Have alook at the cells in the calander area and Named Formulas in the Formulas, Name Manager Tab.

  8. Anand Sant says:

    How can i calculate between two or more different workbooks? Please, reply me as early as possible.

    • Hui... says:

      @Anand
      Open the workbooks you want to link to
      Start a formula = and click and change between workbooks as required.
      You can use the View, Switch window menu to change workbooks mid formula

      The format for using workbooks is
      =[Workbook.xlsm]Sheet1!$A$1
      or
      =SUM('[Book2.xls]Sheet1'!$A$1:$D$10)
      etc

  9. Shemi says:

    Hi Chandoo,
    I am working with a call centre wherein i ned to update at the month end 20 to 30 employees login hours which are defict to track it at the month end is very difficult is there any template which can be made to track that why on a particular day a guy who needs to be on calls was why not on calls.

  10. Denice Lognshaw says:

    Thank you so much Chandoo. This is really helping me. As usual, you rock.

  11. Mukesh Verma says:

    What's FortyTwoDays and Calendar in Name manager?

    Both are unused and FortyTwoDays doesn't make any sense.

  12. Dave says:

    I have a SQL db that contains records of events scheduled/completed on a particular date. Can this method ous building a calendar be used to display those events on the respective day?

  13. Jan Halliday says:

    Positively awesome!
    I'm attempting to help a friend create a schedule for adult classes - and of course its not"paid help".  Here is the scenario:
    20 classes, instructor, room#, student class size, start date, number of class days (need to subtract weekends)

    class
    instructor
    room
    students
    start
    #days

    PATH
    karen
    201
    21
    01/01/13
    11

    BILLING
    jane
    401
    15
    01/12/13
    13

    MEDISOFT
    mike
    301
    11
    01/25/13
    9

    he'd like to see these classes show up in different colors within the same month's calendar chart.  He can draw it, but I'd like to see it done automatically through data, and I just can't visualize it, but I KNOW this will work - can you help?
    Jan 🙂
     

  14. Chan Tean says:

    Dear chandoo,

    Try many way to download still can't access. Any way we want to try out 3 shifts with 3 guys in a group .eg Group A Morn, Group B Night and Group C Rest. And every each group must work on sunday to take turns. In fact we are security teams so that's why sunday is required to work. Pls guide and show how to put in the working calendar. Thank you in advance.

  15. Veronica Burggren says:

    I've been trying to copy and/or recreate this to use in a workbook I'm doing for the transportation department I'm working for. I need to have the calendar on the first sheet in my document (it has graph's from data on another sheet). I'm trying to use it to track (with the conditional formatting) accidents and injuries. I've redone the conditional formatting to do 4 different accident types (no injury, near miss, OSHA recordable injury and work loss injury), but when I enter the formula's you have in the calendar portion where it says "DateOfFirst-FirstWeekDay" I can't figure out how you did that. Are you able to help?

  16. Pipin Fantom says:

    I would like to use Excel to solve the following problem for a community work. I want to create a Driver schedule for a given month from a pool of volunteers for a community service. Each of these volunteers can drive only on specific days in a week. I would like to populate the driving schedule for each weekday with primary, secondary and tertiary drivers in a random fashion so that I do not overburden one person. I would greatly any help you can provide.

  17. Ravichandra says:

    Hi chandoo,
    Thanks for your valuable effort for create this template and let me know how to add multiple employees in the the Roaster.

  18. Savitha says:

    Hi Chandoo,

    This article on shift roaster is very helpful. Could you please let me know how i can use the same for n number of resources who work 24/7, considering their leaves and holidays?

    Thanks,
    Savitha

  19. Balu says:

    Hi Chandoo,

    This article on shift roaster is very helpful to all. Could you please let me know how i can use the same if I want to add for some more shifts, since the color is not getting change if I add more shifts like 4,5 etc.,

    Thanks,
    Murali

  20. Sarah says:

    How can I change the date to 2017 under Shift Data worksheet.

Leave a Reply