Using If and Vlookup Statement together - excel

I am trying to change the Master Key to a “new key” if the origin and destination match the old key.
Basically the master key from table 1 will look to see if the key exsists in Table 2, if it does it will pull the new Key. If the master key does not exist in Table 2 it will not change. It will be the original origin and destination.
I have tried using if statements with vlookups however I am getting stumped with the logical error. Does anyone know how to return the new value or if there is another way to solve this?
I have attached an example.
In the example, in table 1 the Master key is made from London and Italy together. This master key needs to be looked up in Table 2 (located in Column A) If it’s there it will pull the New Key (Column D).

Try this formula in D2 of Sheet1 and drag it down,
=IFERROR(VLOOKUP(A2,Sheet2!A:F,4,FALSE),A2)

I would use an Index/Match solution rather than a vLookup. vLookup is great for simple tasks, but it doesn't usually work whenever you try to do anything more complicated. I now find it is a simpler solution almost everytime (though I am not sure how it compares in performance).
Try something like this in your table1 cell D2:
=IFERROR(INDEX(Sheet2!$A$2:$F$4,MATCH(Sheet1!A2,Sheet2!$A2:$A4,0),4),Sheet1!A2)
What this will do is starting with the Match portion:
It will check the list in Sheet2 A2:A4 for a match of the same string as in Sheet1 cell A2. If it finds it, it will return a row number, if not it will return an error.
Next, the INDEX takes your second table as a source, and uses the row number determined in the Match and the fourth column (which is column D), and returns that value. If the Match returns an error, this will also return an error.
So, we use the IFERROR to capture the situation where the MasterKey in Table 1 does not exist in table 2. In that situation, I am assuming you just want to keep the same MasterKey from Table 1, but you can change that to anything you like.
If that works, you simply drag the formula down from Sheet1!D2 down to Sheet1!D4. Also, if your Table2 is much bigger then you have shown, you will need to adjust the Index and Match inputs to reference the correct range size. Keep in mind the use of "$" as they will prevent the formula from changing those cells when you drag it down.

Related

Find value in the same row of another value that has been looked up?

I looked up values from another sheet with the following formula:
=IFERROR(INDEX('Detail list'!$H$2:$H$1604;SMALL(IF(1=((--(A$1='Detail list'!$J$2:$J$1604))*(--(A$2='Detail list'!$I$2:$I$1604)));ROW('Detail list'!$H$2:$H$1604)-1;"");ROW()-2));"")
This lookup is based on two criteria: Company name and year.
The lookup happens in cell A3 and onwards. It uses the company name in A1 and the year from A2 and then finds a corresponding value in another sheet. There's duplicates involved here since the column that is used for this look up consists only of 001 up til 010. It still is able to return all the values in the correct sequence based on year and company name.
I now want to look up or couple a 'corresponding' value with the value that was just acquired. For example: The value in A3 (005) refers to a specific cell in the other sheet. I want to return a value from that exact row but a different column. I have tried the following:
=IFERROR(#INDEX('Detail list'!$B$2:$B$1604;AGGREGATE(15;6;(ROW('Detail list'!$H$2:$H$19883)-ROW('Detail list'!$H$1))/('Detail list'!$H$2:$H$19883=A3);COUNTIF($A$3:$A3;A3)));"")
This does return a value (namely a client value) but this it is not precise as it takes the first 005 it comes across in the full list (so no longer sorted on year and company!) and reports that. I need it to be from the exact row the previous value is referring to.
I'd be so happy if anyone could help me out with this one. If not, I understand completely,
Kind regards,
VHes
Keeping references consistent and clear across sheets while nesting statements can be tricky. Have you considered pasting the data from 'Detail List' into your current sheet and using something like VLOOKUP or INDEX that way?
Another possible solution would be to throw everything into a pivot table and use the filters to get what you need. Not sure if either of these apply to your task.

Two formulas I'm having issues with

this is my first time asking a question here, but I have two formulas that I'm not really sure why they aren't working.
The first issue I'm having is with this formula:
=MAX(IF(C46:C51<80,B46:B51))
Any reason that this formula returns #VALUE! I'm supposed to find the max value of data in column B so long as the data in column C is less than 80.
Then I'm having issues with VLOOKUP on two questions, that are related I have a large dataset on a separate worksheet. I need to VLOOKUP someone's name to find a value associated with that name. The problem is that their name comes up multiple times. The formula I have for it so far is:
=VLOOKUP('PDR DATA'!E80,'PDR DATA'!A4:V119,15,FALSE)
Where 'PDR DATA'!E80 is the first instance of the person's name appearing. However, using FALSE with VLOOKUP returns #N/A, but if I use TRUE it returns the very last value from column 15 even though the name is different from what I'm searching for. I'm lost here and don't know where to turn.
=MAX(IF(C46:C51<80,B46:B51,C46:C51)) works for me. (Please ensure B46:B51 & C46:C51 has integer values)
=VLOOKUP(cell you want to lookup for, cells where you want to lookup(maybe more than one column), which column you want to fetch from (number), rangelookup) try to understand the syntax and give your inputs
ex: If I have a existing data with Name and id in sheet2, need that id in sheet1 by using the name then I will use =VLOOKUP(L2,Sheet2!A2:B5,2,TRUE)
L2 is the sheet1 name, then I have selected both columns(A,B) and rows in sheet2, then column number is 2.

Excel Function Return Max Two Values

I am looking to get some help with a function that I am sure is an option but I sadly have no clue on how to implement.
Basically, I'd like a formula to go from C21:C50 and look for the top two values. Based upon which two are the top, it would reference the name in B column and populate that value in the another cell (the cell the formula resides in)
If you look at the image, in the primary field, we'd have Steve. Secondary would be Alan.
Is this something anyone can help with? I simply am lost :(
Try
=INDEX($B$3:$B$7,MATCH(LARGE($C$3:$C$7,ROW(A1)),$C$3:$C$7,0))
with Bob in cell B3 and the "primary" formula in cell C9. Copy down to cell C10.
If dealing with integers, you can simply add +1/ROW([range]) to avoid doubles:
=INDEX($B$3:$B$7,MATCH(LARGE($C$3:$C$7+1/ROW($C$3:$C$7),ROW(A1)),$C$3:$C$7+1/ROW($C$3:$C$7),0))
This is an array-formula and must be confirmed with ctrl+shift+enter!
However, this may fail for numbers like 5.01 or 4.99. For that case just use it in combination with RANK.EQ:
=INDEX($B$3:$B$7,MATCH(LARGE(RANK.EQ($C$3:$C$7,$C$3:$C$7,1)+1/ROW($C$3:$C$7),ROW(A1)),RANK.EQ($C$3:$C$7,$C$3:$C$7,1)+1/ROW($C$3:$C$7),0))
This is an array-formula and must be confirmed with ctrl+shift+enter!
The steps as picture:
The first table shows the direct adding of 1/ROW which is used for LARGE and MATCH to get the row if doubles exist (so INDEX can pick the correct one)
The second table shows how the values get replaced by their rank with RANK.EQ and then are treated the same like the first table.
The third (grey) table shows, what would happen if the first formula is applied to the second table (to demonstrate how the ranks get messed up).
For Excel 2007 just replace the RANK.EQ($C$3:$C$7,$C$3:$C$7,1) with RANK($C$3:$C$7,$C$3:$C$7,1).
If you still have any questions, just ask :)

VLOOKUP with criterias from both row and column

I have a big table like this (imagine round-robin result table) where both column and row are team names that First row will be exactly like First Column
Because the table is very big so it is hard to look up for value if I have to look for multiple values
So I'd like to create a table like this
Let's say I want to look up the first "?" in this small table. What formula can I use to look up A2(column)xA3(row) from the big table?
I hope I made it clear enough.
Any pointers or resource I could read online would be greatly appreciated.
I would break this down in two parts.
Get a lookup working for row values using VLOOKUP(). Here is an example: VLOOKUP($A3, BigTable!$A$2:$CW$101, 2, 0):
$A3: Lookup value to find. Dollar sign locks just the column so that when you drag the formula across A doesn't change
BigTable!$A$2:$CW$101: Range to find the result. Dollar sign completely locks the range so wont change
2: Column to bring back (For the time being it is always going to bring back second column)
0: Look for an exact match
Get a lookup working for the column values so that when the formula is copied across it automatically updates the column that it is looking for. I used MATCH() to find the position of the column value in BigTable. For example: MATCH(B$1, BigTable!$B$1:$CW$1, 0):
B$1: Column header to lookup up the position of in the BigTable. Dollar sign locks the row so when you move it down it remains as 1
BigTable!$B$1:$CW$1: Header column to look through
0: Look for an exact match
Finally put the two pieces of the formula together and check some of the values to make sure that it is working correctly: VLOOKUP($A2, BigTable!$A$2:$CW$101, MATCH(B$1, BigTable!$B$1:$CW$1, 0), 0)
This would then give you one formula to copy across the whole of the SmallTable to lookup up the relevant values in the BigTable.
http://www.contextures.com/xlFunctions03.html
Read example 3, it is exactly like my problem.. Thank #DirkReichel for suggesting Index function, so I could know where even to start.

Excel table default value and data validation without VBA

I have a table in Excel for tracking projects. Whenever I create a new row for the table I'd like it to auto-populate one column that the project has "Not Invoiced". I would ALSO like that this column use Data Validation to only allow either "Not Invoiced" or "Invoiced" as content.
I have been able to make both of these things work, but I cannot seem to make them work together without error! The closest I have gotten:
Put a formula in the relevant column. Have tried both the super basic ="Not Invoiced" as well as an =IF formula based on the blankness of another column. This correctly carries down each time I make a new row.
I then add Data Validation on the column which also works fine at first since my default value from my formula is one of the options, HOWEVER when the project does invoice and I select "Invoiced" I then get an error that I'm violating the above formula. From what I've read selecting something from the drop down should just replace the auto-populated formula, but that doesn't seem to happen, it gives me an error that I've violating the column's formula instead.
I've read multiple places that if you correctly order things (create table, add formula for default value, then add data validation) the above method should work, but it will not for me and I continue to get the error every time I change to "Invoiced".
you can enter the stati "Not Invoiced" and "Invoiced" into cells that are close together, e.g. $G$3 and $G$4. Then, create a named range for $G$3:$G$4, let's say "ValList" (menu: Formula / Define Name).
Imagine column A to be the controlling column, and B the status column ("Invoiced" / "Not Invoiced"). Example for cell B5:
The initial status is =IF(A5=""; ""; $G$3)
The Validation (type "List") must be controlled by a formula =IF(A5=""; " "; ValList)
Good luck!
There's a simple way to do this.
Before you start using a new table, add list data validation to the cell in the first and only row:
Invoiced,Not Invoiced
Then, in the first row of your table in that same cell write:
=IF(TRUE,"Not Invoiced";"Not Invoiced")
This will put Not Invoiced as the default value on every new row that is added to the table and also keep data validation in place. You will still have access on every new row's cell to the dropdown list stored in the initial cell's data validation list parameter.
For some reason, data validation is overwritten if you try the same IF-function approach in reference to another cell, as you described it.
One way to solve this would be to use a helper column.
You can use the data validation list for the entry column, say column A.
You can use a formula in the hidden column B with the formula =IF(A1,"Invoiced","Invoiced","Not invoiced")

Resources