Solved

Conditional VLookup

Posted on 2013-12-11
9
376 Views
Last Modified: 2013-12-11
How do I built a conditional Vlookup?

For example, if source cell = X, then use =VLOOKUP(F1,A1:B2000,2,FALSE)
... where I look-up values from the 2nd column from the lookup range.

However, if source cell = Y, the use =VLOOKUP(F1,A1:B2000,3,FALSE)
... where I now want to look-up values from the 3rd column

EEH
0
Comment
Question by:ExpExchHelp
  • 4
  • 4
9 Comments
 
LVL 31

Accepted Solution

by:
Rob Henson earned 250 total points
Comment Utility
=VLOOKUP(F1,A1:B2000,IF(source=x,2,3),FALSE)
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 250 total points
Comment Utility
Depends on the exact situation as to what the best formula will be, but you can use something like this:

=VLOOKUP(F1,A1:B2000,IF(A1="X",2,3),FALSE)

if A1 only has X or Y.
0
 

Author Closing Comment

by:ExpExchHelp
Comment Utility
Thanks!
0
 
LVL 31

Expert Comment

by:Rob Henson
Comment Utility
Just noticed, the formula as described above will result in an error; A1:B2000 is only 2 columns but you are wanting to return the value from a third column, in amendment below I have changed to C2000 so that we have 3 columns.

You may also be able to use the MATCH function to return the column.

If your source cell (A1 as suggested by rorya) is the same as a column header in the data, you can find the relevant column by matching it in the header row:

=VLOOKUP(F1,A1:C2000,MATCH(A1,A1:C1,0),FALSE)

Thanks
Rob
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:ExpExchHelp
Comment Utility
Rob:

Thanks for chiming in... I appreciate it.

I earlier looked at the VLookup and it appeared to make sense.   However, I didn't get a chance to actually test it (busy morning).

Yes, you're right, the proposed Vlookup didn't work for me either.

Please find attached XLS.  
- Value in A1 is a drop-down (male, female example)
- Lookup values are in K:M
- Based on the ID number, I need all 3 males OR all 3 females (again, just an example) to be shown in column D2:D5.

Please see attached XLS for illustration purposes.

Thanks for the continued help.

EEH
Book1.xls
0
 
LVL 31

Expert Comment

by:Rob Henson
Comment Utility
In your example, the formula would be:

=VLOOKUP($C2,$J$1:$M$4,IF($A$1="Male",3,4),FALSE)

However, would your data set really look like the example in J1:M4?

Normally, I would expect to see a unique ID for each individual name.

Are you trying to filter your dataset based on a specific criteria, eg in your example Male or Female?

See the attached amended file. With the arrangement of Data on Suggested tab, you can then use simple column Filters or Advanced FIlter function to produce the results expected in C:D columns.

To replicate, the file should remember the Advanced Filter settings I used. I assume you are using excel 2003 going by the .xls file name. The AF wizard is in Data menu > Filter > Advanced Filter.

If version assumption is incorrect, the AF is Data tab of ribbon > Sort & Filter Group > Advanced.

AF asks for:
1) Data area
2) Criteria
3) Destination (greyed out if copy to another location is not ticked and will filter in place).

The criteria is A1:A2, the dropdown is now in A2 because I have added a header the same as the data table in A1 which the AF function needs.

Thanks
Rob H
Copy-of-Book1.xls
0
 

Author Comment

by:ExpExchHelp
Comment Utility
Rob:

Thanks... your proposed VLookup looks great.    

I agree, this would be a poor representation of data (using the male/female example).

I only used it for illustration purposes as it doesn't require any insight understanding about my process.    So, for the actual data set, I used a totally different value set (numbers only).

Applying your formula will definitely assist me in this particular work.

Again, thanks!!

EEH
0
 
LVL 31

Expert Comment

by:Rob Henson
Comment Utility
No worries, is this related to the Dynamic Drop Down question you also have open?
0
 

Author Comment

by:ExpExchHelp
Comment Utility
Rob - thanks.  No, this is a different problem.

EEH
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now