MS Excel: IF and AND nested - excel

Can someone help with simple excel look up function: How can I pull assigned doctors from the table?
All other cities
and countries Chicago Boston Atlanta California Dallas
General Lee John
Pediatrics Greg
Dermatology Greg Peter Lee
Optholmol Greg
Radiology Mary
Surgery Greg Mary Greg
For ex., Dermatology and Boston should return Peter, but Dermatology from any other city should return Greg

This is a Formulaic answer (no macros or VBA):
If you have a table set up like this:
And on another sheet or range you desire this as your output:
You can use this formula, assuming that the input is in A2 and B2, and the table is on Sheet2 in the range of A2:G8:
=IF(
IFERROR(
INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0)),0
)=0,
INDEX(Sheet2!B2:B8,MATCH(A2,Sheet2!A2:A8)),
INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0))
)
To explain:
The formula: INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0))=0 will test to see if a Doctor exists for the given pair of lookup values.
This formula is getting the row and column value from the array specified:
IFERROR(INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0)),0)=0
^^ array ^^ ^^ match the row ^^ ^^ match the column ^^ ^^ True if no doctor is found
If no doctor exists then we can return a lookup from B2:B8 which is the "All other cities and countries list": INDEX(Sheet2!B2:B8,MATCH(A2,Sheet2!A2:A8))
If one does exist we can just output that doctor: INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0))

Related

INDEX MATCH with Two Criteria - Error w/ Cell Autofill

I am working on a hiring trends report and have an Excel table with multiple entries per ID/individual (as several individuals have left and been rehired over years). The table looks something like this:
WORKSHEET: SHEET1
A B C D
ID Name Location Hire Date
1122 Karen Chicago 01/01/2018
1038 Tom Chicago 05/22/2016
2845 Angel Pittsburgh 11/15/2016
1122 Karen New York 10/08/2013
4992 Mallory Seattle 09/14/2015
2845 Angel Pittsburgh 07/21/2011
1122 Karen Pittsburgh 08/22/2011
I have created a new table with only one entry per person and their most recent hire date. The next step is to populate the table with location data based on the person's ID and specified hire date.
My approach was to use an INDEX-MATCH expression with two match statements (one for ID and one for hire date):
=INDEX('SHEET1'!$C$2:$C$2000,
MATCH('SHEET2'!A2,'SHEET1'!$A$2:$A$2000,0),
MATCH('SHEET2'!D2,'SHEET1'!$D$2:$D$2000,0))
The first row where I enter the expression retrieves the correct location data. However, when I attempt to populate the remaining rows in that column, I get a #REF! error, as illustrated below.
WORKSHEET: SHEET2
A B C D
ID Name Location Hire Date
1122 Karen Chicago 01/01/2018
1038 Tom #REF! 05/22/2016
2845 Angel #REF! 11/15/2016
4992 Mallory #REF! 09/14/2015
I've tested each INDEX-MATCH expression separately (first testing for a match only on ID and then testing for a match only on hire date). Each one works separately, and as shown above, it does work for the first row--it just will not autofill for other rows. I've also checked SHEET1 and each individual definitely has the correct matching criteria on SHEET2 for referencing.
Can anyone help with either suggesting a way to fix my expression or an alternative way to retrieve the location data based on two criteria? Thanks in advance!
The third argument to INDEX is the column number, which is why you get a #REF error. You can use LOOKUP instead:
=LOOKUP(2,1/('SHEET2'!A2='SHEET1'!$A$2:$A$2000)/('SHEET2'!D2='SHEET1'!$D$2:$D$2000),'SHEET1'!$C$2:$C$2000)
you can use this formula :
=INDEX(Sheet1!C1:C2000;MATCH(1;INDEX((Sheet1!A1:A2000=Sheet2!A1)*(Sheet1!D1:D2000=Sheet2!D1);0;1);0))
so you can use more than one criteria in secend index like this:
=INDEX((criteria1)*(criteria2)*(criteria3);)

Vlookup from another sheet using multiple columns

I have an excel workbook with 2 sheets.
Sheet 4 and Sheet 5:
Sheet 4 has the following columns:
type model name year
U acura jane 1998
D honda peter 2002
U bmz fred 1993
Sheet 5 also has the same columns but with an additional column sales.
type model name sales
U acura jane 2.3
D honda peter 3.8
U bmz fred 19
IN both the sheets, I created an additional column called "key" concatenating type-model-name (A2&B2&C2)
type model name year key
U acura jane 1998 Dacurajane
D honda peter 2002 Dhondapeter
U bmz fred 1993 Dbmzfred
To get the sales in Sheet1, I am giving the following vlookup.
=VLOOKUP(E2|Sheet5!A2:F4|5|FALSE)
I looked at other similar answers, trimmed the columns and did what the recommendations were, but it still returns #N/A
Can anyone point out what my mistake it?
Thanks In advance.
Use INDEX/MATCH
=INDEX(Sheet5!D:D, MATCH(E2, Sheet5!A:A&Sheet5!B:B&Sheet5!C:C, 0))
Enter with Ctrl-Shift-Enter
Also I am assuming that the sales is in column D of Sheet5. If different, put the appropriate column in as first parameter to the INDEX function.
Also please consider using restricted range references in the match function, instead of full column references - for speed & efficiency.
on cell E1 you will have KEY on cell E2 you will place =CONCATENATE(A2,B2,C2,D2) Combines contents above into a phrase "DFocusManuel2016". That should work for the combine part just paste that and drag down as desired on E2.
You can cover the rest of the cell population by simply assigning links to the cells so on cell A2,B2,C2 and D1 you will have =SHEETNAME!Y10 which Y10 corresponds to the source cell and Sheet name to the source sheet.

If Cell Contains XXX Then Return Corresponding Value

A B C D
1 Ross Sales John Guys Finance
2 Smith Sales Sam Andy #N/A or False
3 Guys Finance Mike Ross Sales
I'm putting this formula in cell "D1" but it's not giving me correct result
=IF(SUMPRODUCT(--ISNUMBER(SEARCH(A:A,C:C)))>0,B:B)
INDEX MATCH function would not work because it's not exact value
What can I put in "D1" and down to give me result as in the table above?
Try this in D2,
=LOOKUP(1E+99, SEARCH(A2, C:C), B:B)
'or cut down the full column references
=LOOKUP(1E+99, SEARCH(A2, C$2:C$4), B$2:B$4)
'alternately as a wildcard MATCH
=INDEX(B:B, MATCH("*"&A2&"*",C:C, 0))
Fill down as necessary.
      

Excel: match value from an array and return cell value from the same row

I have some data in excel worksheet1 in this form:
person1 person2 person3 score
dave sarah jill 4
brandon hank 3
And in worksheet2 I have a column of people listed alphabetically, like this:
person score
alex
brandon
dave
hank
jill
sarah
I'd like to obtain each person's score from worksheet1 (with blanks for those who are absent):
person score
alex
brandon 3
dave 4
hank 3
jill 4
sarah 4
I've looked into functions like find, match, lookup, vlookup, but it seems like I will need something more complicated.
Assuming:
Each person can only ever occur once in the source data
The source data occupies the range A1:D3 (with headers in row 1)
The first person's name for which you wish to return a result is in G2
then this formula in H2:
=IF(COUNTIF($A$2:$C$3,G2),INDEX($D$2:$D$3,SUMPRODUCT(($A$2:$C$3=G2)*(ROW($A$2:$C$3)-MIN(ROW($A$2:$C$3))+1))),"")
Copy down to give equivalent results for names in H3, H4, etc.
Regards

Match Value in Cell to an Existing Column and Return Adjacent Cell Text

I have a spreadsheet containing patients in column a, patient's diagnosis in column b, and their doctor in column c. I have another sheet that has the doctors listed in column a and their practice group in column b. I need a function that will look at each value in column c on sheet 1, match it to the doctor in column a on sheet 2 (Doctors List), and return the practice group to column d on sheet 1. I have tried a few formulas including this one
=IFERROR(VLOOKUP(C2,'Doctors List'!A:B,2,FALSE),"")
but can't seem to get anything to work! It just returns blanks. Please help!
**SHEET 1
Patient Name Diagnosis Attending Physician Practice Group**
Patient A Diagnosis Dr. Smith
Patient B Diagnosis Dr. John
Patient C Diagnosis Dr. Joe
Patient D Diagnosis Dr. Ken
Patient E Diagnosis Dr. Williams
Patient F Diagnosis Dr. Williams
Patient G Diagnosis Dr. Smith
Patient H Diagnosis Dr. Jones
**SHEET 2
Physician Practice Group**
Dr. Smith Practice A
Dr. John Medical Group A
Dr. Joe Practice B
Dr. Ken Medical Group B
Dr. Williams Practice C
Dr. Jones Medical Group C
Try using MATCH and INDEX rather than VLOOKUP
So in D2 of sheet 1:
=INDEX(Sheet2!$B:$B,MATCH($C2,Sheet2!$A:$A,0))
and copy that formula down.
If you're looking to troubleshoot, your existing formula, try using "Evaluate" on the Formulas tab of Excel 2010 which can step you through the calculation.
I've had problems with text fields that have extra spaces after them, so I regularly use the "TRIM" function when doing lookups, or matches.

Resources