Index/Match with multiple possible answers? - excel

There's a question about how to return some info in Excel, COUNTIFS for VLOOKUP. from #THATNewbie.
Here's a quick summary:
They have this table:
Report Name User Name Report Category
Report 1 John Smith Sales
Report 1 Jack Black Sales
Report 1 Connie Rae Sales
Report 1 Brain Bonds Sales
Report 2 John Smith Sales
Report 2 Connie Rae Sales
Report 3 Jack Black Inventory
And they would like to return the "Report Name" based on User Name and Report Category.
My first thought was just to use Index/Match (as an Array)...however, I realize that if I use "John Smith" and "Sales" to look up the Report Name, there's two possible outcomes: Report 1 and Report 2. Index/Match will always return Report1 (or whatever comes first, going down that column).
My question is: Is there a way to write the Index/Match formula to check if it's already found Report1 and therefore to go to the next match (Report2)?
Here's a screenshot to help visualize. As you can see, the Index/Match correctly finds Report1 in C12, but also in C13. Can you have the formula "look above" and if it's the answer that it WOULD return, to skip that and look for the next? Does that make sense?

You can try something like this:
=INDEX(Report_Name,MATCH(The_User&":"&The_Category,User_Name&":"&Report_Category,0))
The idea is to concatenate user name and report category into a single search item. (I added a colon char as a delimiter; this was optional and could possibly be omitted.) Then use MATCH to get the index of the matching item, and INDEX to convert the index to a specific report.
Hope that helps.

Unfortunately there is no way (to my knowledge) to do this. You will have to add some sort of unique identifier to each row, or a value that helps define it uniquely. For example, you could add a new column with this function
=COUNTIFS($B$2:$B2, "=" & $B2, $C$2:$C2, "=" & $C2)
What this will do is count the total number times that that specific grouping has shown up, and effectively act as a pseudo ID for it. Then you can add that item to your Index/Match
Then in the second table you showed in the image, you just repeat the count function in the match, so you will have
=INDEX($A$2:$A$8, MATCH(1, (A12 = $B$2:$B$8) * (B12 = $C$2:$C$8) * (COUNTIFS($A$12:$A12, "=" & $A2, $B$2:$B2, "=" & $B2) = $D$2:$D8), 0))
This is an array entered forumla

My question is: Is there a way to write the Index/Match formula to
check if it's already found Report1 and therefore to go to the next
match (Report2)?
Yes, but a simpler way it can be done is using index & small.
Index & small
Need to CTRL+SHIFT+ENTER. Copy down for remaining rows.
{=INDEX($A$2:$A$16,SMALL(IF(A19=$B$2:$B$16,IF(B19=$C$2:$C$16,ROW($B$2:$B$16)-ROW($B$2)+1),""),ROW(B2)-1))}
Where A19 & B19 contain cells for search criteria.
Using Index & Match;
This could possibly be simplified but shows the steps.
Add another column alongside the search criteria area & change the formulas as below.
Need to CTRL+SHIFT+ENTER.
Column C (Report Name);
Following for the first row or search criteria item only
{=INDEX($A$1:$A$16,MATCH(A21&B21,$B$2:$B$16&$C$2:$C$16,0)+ROW(A2)-1)}
Copy following down for the remaining rows items.
{=INDEX($A$1:$A$16,MATCH(A22&B22,INDIRECT(CONCATENATE("B",E22,":","B16"))&INDIRECT(CONCATENATE("C",E22,":","C16")),0)+ROW(INDIRECT(CONCATENATE("B",E22)))-1,1)}
Column E - helper column. Helper column returns the start of the next row.
First row item is N/A.
Following for 2nd or search criteria item only.
{=MATCH(A22&B22,$B$2:$B$16&$C$2:$C$16,0)+ROW(A2)}
Following copy down for remaining rows.
{=MATCH(A23&B23,INDIRECT(CONCATENATE("B",E22,":","B16"))&INDIRECT(CONCATENATE("C",E22,":","C16")),0)+ROW(INDIRECT(CONCATENATE("F",E22)))}
This however does assume the search criteria is the same, unlike the other question referred to. If search criteria is different or more complex refer to
COUNTIFS for VLOOKUP

Related

How can you in Excel total predefined values depending on cell values

I have a spreadsheet with two tabs. The first one contains Vehicle Types and a numeric score value.
Second Tab has like a variety of these vehicle types and what should be the total score. Depending on the vehicle types present in the respective neighbour cell.
See images below for illustration.
Is there a way via formula to get the total, in Column B in sheet 2, of the corresponding numeric values of column a from sheet 1?
For example, as per the illustration B2 in sheet would total 3; whereby in sheet 1 bus has a score of 1 and car 2.
Update:
As per the answer below, I have used the formula;
=SUMPRODUCT(ISNUMBER(FIND(" "&sheet1!A$2:A$4&" "," "&SUBSTITUTE(A4,CHAR(10)," ")&" "))*sheet1!B$2:B$4)
However, I am unfortunately getting zero as the value. Changing the line breaks in column A in sheet2 I am duly able to get the total. Is there a way to do it so irrespective of how the list is presented in the column the total will work?
I think you are after something like this:
Formula in E2:
=SUMPRODUCT(VLOOKUP(FILTERXML("<t><s>"&SUBSTITUTE(D2,CHAR(10),"</s><s>")&"</s></t>","//s"),A$2:B$4,2,FALSE))
If one has O365 you could just use SUM instead since it would auto-CSE the formula.
If you don't have Excel 2013 or later, you could try the following as another option (shorter but not my favourite):
=SUMPRODUCT(ISNUMBER(FIND(" "&A$2:A$4&" "," "&SUBSTITUTE(D2,CHAR(10)," ")&" "))*B$2:B$4)

Return second (and subsequent) unique name in list

I have a list of data that I get from a third party. For simplicity, lets say that Column A is the Unique ID (alpha-numeric), and Column B is the employee who is assigned to that ID. One employee has several ID's, as they work several cases at a time. A few of the Unique ID's begin with "AC", and these ID's are special cases.
I need a formula that will search through Column A on the "Raw Data" sheet for any license number that begins with "AC", and return the Assigned Employee name on my "Assigned Employees" sheet. This is easy enough for the first one with a simple index match formula. However, I need it to bring back the second name, and any other names that are there. In the example below, I would need it to bring back Paul, then Lee.
Column A Column B
Unique ID Assigned Employee
AC798358 Paul
90807248 Paul
AC48298 Lee
B98281 Lee
AC42795 Lee
The table on "Assigned Employees" looks like this:
Employee 1 Employee 2 Employee 3 Employee 4
Paul Lee
I'm using this index match formula to get the first return (Paul), but it will only work for the first "AC" ID number on the sheet.
=INDEX('Assigned'!$B:$B,MATCH("AC*",'Assigned'!$A:$A,0))
I'm trying this formula, which would bring the first and subsequent returns by changing the "k" number for the "Small" function, but it's not working for me.
=INDEX('Assigned'!$B:$B,SMALL(IF('Assigned'!$A:$A="AC*",ROW('Assigned'!$A:$A)-ROW(INDEX('Assigned'!$A:$A,1,1))+1),1))
I know that it doesn't like this part: IF('Assigned'!$A:$A="AC*", but I don't know how else to write it to make it work. Any help would be appreciated.
Possibly relevant: there are a lot of blank rows in this data set.
There is a standard array formula method for pulling a unique list from a list of duplicates. For your sample data, put this in D2, finish with ctrl+shift+enter (aka CSE) then drag right.
=INDEX($B2:$B10, MATCH(0, COUNTIF($C2:C2, $B2:$B10), 0))
You can add conditions (e.g. IF(LEFT($A2:$A10, 2)="AC") to this.
=INDEX($B2:$B10, MATCH(0, IF(LEFT($A2:$A10, 2)="AC", COUNTIF($C2:C2, $B2:$B10)), 0))
This style of LISTUNIQUE formula requires an unused cell to the left (or above if listing into rows). If you don't have the room for an unused cell to the left or above, you could avoid that by using a more conventional formula to achieve the first item in the list and modifying the second to use the first as its reference starting point.
'in D2
=INDEX(B2:B10, MATCH("AC*", A2:A10, 0))
'in E2 (with CSE and dragged right)
=INDEX($B2:$B10, MATCH(0, IF(LEFT($A2:$A10, 2)="AC", COUNTIF($D2:D2, $B2:$B10)), 0))
You can avoid the #N/A errors when you run out of matching items with a wrapping IFERROR function.

Return Value if 4 columns match in Excel

I have 2 sheets that I am working with in Excel:
1) Master Price Sheet
2) Entry
My "Master Price Sheet" sheet includes specific lumber dimensions and specifications as well as an assigned pricing (There are probably 200 different options available for pricing purposes so it takes a long time to manually look up each price)
When I am entering lumber lists into my "Entry" sheet. . .I'd like to return the value from the column "Price" from the "Master Price Sheet" only if the values in columns "Size (W)", "Size (H)", "Length", and "Species" entered into the "Entry" sheet matches columns in the "Master Price Sheet" so that it can find the pricing for me
What formula would be able to help me out with this?
Any help you can provide would be greatly appreciated
I've added images to this post below so that you can see what I'm working with
The easiest way is probably to create a helper column in both tables, where you combine the four cells with an ampersand & sign. This will create a unique key that you can use in a lookup function like VLoookup or an Index/Match combination.
For example: in the Master table, insert a new column before the price and in that new column use the formula (starting in cell G3
=A3&C3&D3&E3
Do the same in the Entry sheet table. Then you can look up the price like this in cell H3 of the entry table:
=vlookup(G3,'Master Price Sheet'!F:G,2,False)
Copy down.
This is the basic principle. You can add more refinement by error catching, so you don't get errors if rows are empty. One of many approaches would be to wrap the formula in an IfError, or check that all four cells have content before performing the Vlookup.

excel: if cell contains multiple criteria then return multiple criteria, nestled?

I have 4 criteria lists that look like this:
A B
Name Category
Name Category
Name Category
And a MasterList like this:
A B
stuffNAME Category
NAMEstuff Category
NAME Category
I would like to know if there is a formula that can search through each criteria list based on the MasterlistA column for "NAME" and return the appropriate "Category" in MasterlistB.
As an example:
I'm looking to return MasterlistB based on MasterlistA
Criteria List:
A B
NBC NBCU
Disney ABC
Masterlist:
A B
NYC NBC 20998 NBCU
NJ2987 NBC NBCU
Disney Florida99 ABC
I'm simplifying, but in reality the criteria lists all refer to different masterlist columns as well. Trying to get the matching/searching part down first.
Given a setup as shown in #ScottCraner 's answer:
In cell E1 and copied down:
=IFERROR(LOOKUP(1,1/COUNTIF(D1,"*"&$A$1:$A$2&"*"),$B$1:$B$2),"No Match")
This is a regular formula and does not require array entry.
You can do this using VLOOKUP, nested with the IFERROR statement.
I am assuming each table is starting on A1, in sheets called Sheet1, Sheet2, Sheet3, and Sheet4. You may need to adjust references to point to appropriate tables.
The basic formula to find the category which matches your name, is simply [assuming your search term is on a new sheet on A1, let's say Sheet5, with the rest of your final data table]:
=VLOOKUP(A1,'Sheet1'!A:B,2,0)
This simply takes the value in A1 [the search term], tries to find it in column A of sheet 1, and if it does find it, takes the first matching row, and returns the value on the 2nd column in [column B, with the category].
If that fails, you simply put that inside of IFERROR, which attempts to calculate something, and if it creates an error, returns something else, like so:
=IFERROR(VLOOKUP(A1,'Sheet1'!A:B,2,0),"NO MATCH FOUND")
Now to use the IFERRORS to first attempt to find a match on Sheet1, then Sheet2, etc., put the following:
=IFERROR(VLOOKUP(A1,'Sheet1'!A:B,2,0),IFERROR(VLOOKUP(A1,'Sheet2'!A:B,2,0),IFERROR(VLOOKUP(A1,'Sheet3'!A:B,2,0),VLOOKUP(A1,'Sheet4'!A:B,2,0))))
To search for only a partial match, you can use the following:
=VLOOKUP("*"&A1&"*",'Sheet1'!A:B,2,0)
The "*" act like wildcards, and if they are included in front of and behind your search term [in this case, A1], then anything that contains your search term, regardless of its position in a cell, will be considered a match. You can replace A1 in all of my above formulas with this revised wildcard match to check for partial matches in any of your sheets.
To search a list of items, which exactly match a part of your search term
You could probably do this with an array formula, but because you have multiple data tables, I think the easiest solution is to use a helper column next to each of those tables, to create a unique ID which actually matches to your Master List. ie:
On Sheet1 [and all other category sheets], insert a new column in between A & B; this column will trace back from column A, to match a Name from your Master List on Sheet5, like so [starting in B1 & copied down]:
=VLOOKUP("*"&A1&"*", 'Sheet5'!A:A, 1, 0)
Your revised formula in your master sheet would now look like this:
=IFERROR(VLOOKUP(A1,'Sheet1'!B:C,2,0),IFERROR(VLOOKUP(A1,'Sheet2'!B:C,2,0),IFERROR(VLOOKUP(A1,'Sheet3'!B:C,2,0),VLOOKUP(A1,'Sheet4'!B:C,2,0))))
Rather than placing the four lists side-by-side like:
Stack them on top of each other like:
The its as simple as:
=VLOOKUP("David",A1:B12,2)
So here is the basic formula to get what you want:
=INDEX($B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & $A$1:$A$2 & "*",D1))),1))
if you have 2010 or later. If you have 2007 and earlier than you will need to use the following array formula:
=INDEX($B$1:$B$2,SMALL(IF(ISNUMBER(SEARCH("*" & $A$1:$A$2 & "*",D1)),ROW($1:$2)),1))
It being an array formula it must be confirmed with Ctrl-Shift-Enter.
In the picture, the first formula is Column F, the second in Column E
You will need to add nested IFERROR() Functions for the various sheets.
=IFERROR(INDEX(Sheet1!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet1!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet2!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet2!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet3!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet3!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet4!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet4!$A$1:$A$2 & "*",A1))),1)),"NOT HERE"))))

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

Resources