Excel Lookup Formula with Two Conditions - excel

Sorry about the heading but im finding it hard to explain so ill give it my best shot.
Here is my problem
I have 3 cells: Lender, product and productID I have a vlookup that fills the lender and product cells just fine
However i want a way to bring back the productID back from another worksheet matching with lender and product.
For instance if call1 = newcastle and cell2 = 2 year fixed then cell3 = 422
I tried using a vlookup but doesnt seem to work, Any help on this would be greatly appreciated. Thanks

You can use Index and Match to perform a lookup with two criteria. Here is an example of one from http://blog.contextures.com/archives/2012/07/12/check-multiple-criteria-with-excel-index-and-match/
=INDEX($D$2:$D$10,MATCH(1,(A13=$B$2:$B$10)*(B13=$C$2:$C$10),0))
As mentioned on the site, it is an array formula so rather than just pressing enter when you use the formula, you need to hold Ctrl+Shift+Enter.
To break down how the formula is formatted:
=INDEX(a,MATCH(1,(b=c)*(d=e),0))
a = The whole range with all the data in it
b = The first criteria for the data to be filtered on
c = The range in which the first criteria needs to be searched
d = The second criteria for the data to be filtered on
e = The range in which the second criteria needs to be searched
Make sure that you use $ in the correct places as in the above example.

Another alternative to using combination of the MATCH and INDEX functions that some may find more straightforward is to first insert a column on your lookup table and concatenate the cobmination of columns you wish to search by.
=CONCATENATE(B8,C8)
Then you can still use the Vlookup function, but instead of only entering the one column to lookup on, you would combined them in the lookup so that the combination of them looks up to the combination of them on the lookup table.
=VLOOKUP(B3&C3,A9:D10,4,0)

Let's say that Newcastle is in A2 and 2 year fixed is in B2. It doesn't matter what worksheet they are on.In another worksheet named Data you have a table with a column of lenders in column X, products in column Y and product IDs in column Z. There are column labels in row 1 so the real data starts in row 2 and there are 2587 rows of data. In the first worksheet's C2 where you want the double lookup for a ProductID that matches Lende and Product try this formula.
=IFERROR(INDEX('Data'!$Z$2:$Z$9999, MIN(INDEX(ROW($1:$9998)+(('Data'!$X$2:$X$9999<>$A2)+('Data'!$Y$2:$Y$9999<>$B2))*1E99,,))), "no match")

Related

Excel - Check if value X and value Y is on the same row

I have an excel document with two sheets, data and edu-plan. The sheet data has the following information:
The sheet edu-plan looks like this:
My question is: how do i create an excel formula that checks if the target group on the specific row in edu-plan! has the course name in question on the same row as the target group in sheet data!, i.e. if Sales and Sales course is on the same row in the sheet data!?
In reality, the data sheet as a couple of hundred rows and will change over time, so i am trying to develop a formula that i can apply easily on all rows/columns in edu-plan!.
The desired result in edu-plan would look like this:
A pivot table might be a good way to go.
If you would like to do it by formula, then you can just use a COUNTIFS
=IF(COUNTIFS(data!$A$2:$A$10,$A2,data!$B$2:$B$10,B$1),"X","")
A possible way to solve your issue with an array formula:
Write in B2 of sheet edu-plan
{=IFERROR(IF(MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)>0,"x",""),"")}
Since it is an array formula, you need to hit shift + ctr + enter.
Here is the formula broken down:
MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)
checks whether the combination of row header and column header is in the data table. MATCH returns the index of the found combination. Since we are not interested in the location, we only ask IF(MATCH > 0, "x", "") to write an "x" if a match was found. If MATCH finds nothing, it returns an error, which is why we add an IFERROR(VALUE, "") around the construct.

Excel | Searching table in different sheet and bringing value from column in that row

I am trying to lookup a table in one of my sheets. my table consists of three columns and an unlimited amount of rows.
My table can be seen here:
In my second sheet I wish to write a formula which searches all rows in the table and looks for an exact match in column A and column B, this means it must find the row where column a has a value of "jan" and in that same row the second column must have value "y". Should it find this match, it should return the value of column C.
I tried researching hlookup but that is for horizontal tables so i dont believe this would work. I looked into Vlookups also but that only allows one criteria search instead of looking for two matches.
Can anyone shed some light here please?
You can use index and match with multiple criteria
=INDEX($A$1:$C$1000, MATCH("Jan"&"y", $A$1:$A$1000&$B$1:$B$1000, 0),3)
press CTRL + SHIFT + ENTER when entering this formula.
Convert the range to a table (ctrl-t) and then use SUMIFS to search the table based on two criteria
=SUMIFS(Table1[Alteration],Table1[Month],"Jan",Table1[Products],"y")
This is saying "give me [Alteration] where [Month] = "Jan" and [Products] = 'y'...this returns 364.
You can point the criteria at separate cells containing your criteria.
Be aware that if there is more than one row with identical data (ie more than one row with both 'Jan' and 'y'), column C will be summed together.
The INDEX function has the syntax
INDEX(array, row_num_in_array, [column_num_in_array])
And MATCH returns in the index location of a logic match
MATCH(lookup_value, lookup_array, [match_type])
Combining the two is a flexible technique, and surprisingly powerful -- the logic in a match lookup_value can be a complex condition.
SIMPLEST CODE
Operate on the whole column
INDEX(C:C, MATCH("Jan"&"y", A:A&B:B, 0), 1)
nb./ A:A is excel code for "all of column A". You can instead use:
RESTRICTED CODE
Operates on a subset of the sheet.
INDEX($C$2:$C$1000, MATCH("Jan"&"y", $A$2:$A$1000&$B$2:$B$1000, 0), 1)
Note that you MUST use identical row length arrays (eg. rows 2:1000) or the formula will not work. MATCH only knows how many rows into its lookup_array it got, you need to ensure its rows match those in INDEX's array
PS. apologies this is close to the previous answer, but the details were too long for a comment.
PPS. I missed the clarifications to the first answer. That will work, but there is no need to use all three columns as the array in the INDEX function. You are only returning data from column C after all.

How to filter the correct line in sheet instead of IF-statement (Excel)

In my excel sheet i have the following function:
=IF(AD51="European";
IF(P51<50.000.000; 0,05%;
IF(P51<75.000.000; 0,045%;
IF(P51<100.000.000; 0,04%;
IF(P51<125.000.000; 0,037%;
IF(P51<150.000.000; 0,035%;
IF(P51<200.000.000; 0,034%;
IF(P51<250.000.000; 0,033%;
IF(P51<300.000.000; 0,032%;
IF(P51<400.000.000; 0,031%;
IF(P51<500.000.000; 0,03%;0,025)
)
)
)
)
)
)
)
)
);"American")
Well, I need to replace this in an extra sheet in order to avoid this kind of IF function in a cell.
Here the table:
My question is, how to get the result in the marked cells below:
I need to check if the ID is existing in CalcSheet (Screenshot1) and then to check in which rank the Volume value is categorized in MasterSheet (Screenshot2). Finished the table have to return the %-value of the CalcSheet.
EDIT: I tried it with VLOOKUP(A2;Ranking;3) but I get always the
same procent => 0,03. For your information, Ranking is the range of
the Screenshot1 that I named it.
Complex Lookups in Excel
Solution to your problem using SUMIFS
Updated MasterSheet
CalcSheet with Formula
Formula in CalcSheet!C2:
=SUMIFS(MasterSheet!$D$2:$D$11,MasterSheet!$A$2:$A$11,A2,MasterSheet!$E$2:$E$11,E2,MasterSheet!$C$2:$C$11,">"&B2,MasterSheet!$B$2:$B$11,"<="&B2)
Explanation
VLOOKUP is quite limited in its ability to pick up values. This neat trick with SUMIFS allows fairly complex lookup based on multiple conditions. The trick here is to first ensure that you select one and only cell using conditions and then sum over that one cell.
In this case, we sum over column D in MasterSheet. The conditions are:
MasterSheet Column A matches CalcSheet Column A
MasterSheet Column E matches CalcSheet Column E
MasterSheet Column C is greater than CalcSheet Column B
MasterSheet Column B is less or equal to CalcSheet Column B
Please mark this as answer if this solves your problem.
Update in response to OP's comment
Like the above 4 conditions. You can choose up-to 127 ranges and corresponding conditions in Sumifs in Excel 2016. Check this link in Office Documentation.

Find something in column A then show the value of B for that row in Excel 2010

Basically my problem is that I have a string in one cell in excel, I then need to see if that string exists in another row (not one cell but the whole row) and if so then print the contents of another cell in the same row but in another column.
I will give a basic example:
Title Answer
Police 15
Ambulance 20
Fire 89
Now I need to scan the title column for, say, "Police" and then populate the cell with the value under Answer (in this case 15).
I cant just say IF(A2="Police";B2;"" as I need the scan the whole of the Title column.
I have tried using IF(COUNTIF(A$2:A$100;"Police"); which scans the contents of A2 to A100 for the string Police, and know how to make it print a constant (just put something after the ;) but cant work out how to make that "constant" a variable that changes depending on the found row. So if the COUNTIF found Police in cell A44 then the answer to my formula would be B44, the same as if it found Police in A62 then my formula should show B62
I hope this makes sense and that someone can help me :)
Note that I am using excel 2010 and need a normal formula as I can not use scripting for this document.
EDIT:
Here is what I have so far, note that the spreadsheet I am using is far more complex than the "simple" example I have in the question...
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
This is showing "RuhrP" in every answer where "RuhrP" is found in F9 and not the answer I want which should be that found in RuhrPumpen!I$5:I$100 where the cell index is the same as that for the A coloum where A9 was found. Again, sorry for the complexity I cant think of any better way to word it.
I note you suggested this formula
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
.....but LOOKUP isn't appropriate here because I assume you want an exact match (LOOKUP won't guarantee that and also data in lookup range has to be sorted), so VLOOKUP or INDEX/MATCH would be better....and you can also use IFERROR to avoid the IF function, i.e
=IFERROR(VLOOKUP(A9;Ruhrpumpen!A$5:Z$100;9;0);"")
Note: VLOOKUP always looks up the lookup value (A9) in the first column of the "table array" and returns a value from the nth column of the "table array" where n is defined by col_index_num, in this case 9
INDEX/MATCH is sometimes more flexible because you can explicitly define the lookup column and the return column (and return column can be to the left of the lookup column which can't be the case in VLOOKUP), so that would look like this:
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH(A9;Ruhrpumpen!A$5:A$100;0));"")
INDEX/MATCH also allows you to more easily return multiple values from different columns, e.g. by using $ signs in front of A9 and the lookup range Ruhrpumpen!A$5:A$100, i.e.
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH($A9;Ruhrpumpen!$A$5:$A$100;0));"")
this version can be dragged across to get successive values from column I, column J, column K etc.....
Assuming
source data range is A1:B100.
query cell is D1 (here you will input Police or Fire).
result cell is E1
Formula in E1 = VLOOKUP(D1, A1:B100, 2, FALSE)
I figured out such data design:
Main sheet:
Column A: Pump codes (numbers)
Column B: formula showing a corresponding row in sheet 'Ruhrpumpen'
=ROW(Pump_codes)+MATCH(A2;Ruhrpumpen!$I$5:$I$100;0)
Formulae have ";" instead of ",", it should be also German notation. If not, pleace replace.
Column C: formula showing data in 'Ruhrpumpen' column A from a row found by formula in col B
=INDIRECT("Ruhrpumpen!A"&$B2)
Column D: formula showing data in 'Ruhrpumpen' column B from a row found by formula in col B:
=INDIRECT("Ruhrpumpen!B"&$B2)
Sheet 'Ruhrpumpen':
Column A: some data about a certain pump
Column B: some more data
Column I: pump codes. Beginning of the list includes defined name 'Pump_codes' used by the formula in column B of the main sheet.
Spreadsheet example: http://www.bumpclub.ee/~jyri_r/Excel/Data_from_other_sheet_by_code_row.xls
Guys Its very interesting to know that many of us face the problem of replication of lookup value while using the Vlookup/Index with Match or Hlookup.... If we have duplicate value in a cell we all know, Vlookup will pick up against the first item would be matching in loopkup array....So here is solution for you all...
e.g.
in Column A we have field called company....
Column A Column B Column C
Company_Name Value
Monster 25000
Naukri 30000
WNS 80000
American Express 40000
Bank of America 50000
Alcatel Lucent 35000
Google 75000
Microsoft 60000
Monster 35000
Bank of America 15000
Now if you lookup the above dataset, you would see the duplicity is in Company Name at Row No# 10 & 11. So if you put the vlookup, the data will be picking up which comes first..But if you use the below formula, you can make your lookup value Unique and can pick any data easily without having any dispute or facing any problem
Put the formula in C2.........A2&"_"&COUNTIF(A2:$A$2,A2)..........Result will be Monster_1 for first line item and for row no 10 & 11.....Monster_2, Bank of America_2 respectively....Here you go now you have the unique value so now you can pick any data easily now..
Cheers!!!
Anil Dhawan

How to match 2 columns in excel?

I have an excel sheet, sheet1 which has 2 cols, A and B. Col A has some values and has corresponding mapping in col B(not all values in A have a mapping in B, some are empty). The sorting is done from Z-A and w.r.to Col A. I have another excel sheet, sheet2 which has similar Col A and Col B. Now, i want to find out whether any match is there between Col A of sheet1 and Col A of sheet2. If matches are found, those values should be copied onto a new column.
=VLOOKUP(Sheet1!L24,E24:F27,2)
I thought I might give a better explanation because i didn't feel any of these were useful for me to personally figure out VLOOKUP and this answer came up high on list of google when looking for VLOOKUP Examples.
Here is my example which is looking up data from one worksheet to another:
=VLOOKUP(I2,Sheet1!$A$2:$Q$338,2,FALSE)
which is:
=VLOOKUP(<NEEDLE>,<HAYSTACK>,<COLUMN OF HAYSTACK TO PULL BACK INTO LOOKUP COLUMN>,<LEAVE AS FALSE>)
Steps:
Select the column which is looked up as the <NEEDLE> eg lookup_value . This might be a list of cars
Then select the entire range of the data you want to search within as <HAYSTACK> eg table_array. This is simply a selection of a range of which data to search through. It can be range within the current worksheet, or a range on a different tab/worksheet
give a number which is index of column in the Haystack of which column you would like returned as the value. eg col_index_num
supply "false" as final paramater. this should always be false at least in the cases I've used it.
I hope that helps someone else.
It is possible to do a lot with Excel and ADO: Excel VBA to match and line up rows

Resources