Excel table Lookup values - excel

I have a table-1 like this:
NAMES ID
John 1
Bill 2
May 1
Silvia 1
Sam 3
Oren 2
Another table-2:
ID_To_Compare name1 name2 name3
1
2
3
I would like to have in table-2 function that gets result like this, according to ID_To_Compare (seeks it in table-1):
ID_To_Compare name1 name2 name3
1 John May Silvia
2 Bill Oren
3 Sam

An Excel lookup looks like this;
=VLOOKUP(I7;Sheet1!$A$2:$F$250;2;FALSE)
The first part (I7 in this case) is the value of the key to find.
The second part (Sheet1!$A$2:$F$250 in this case) is the range to search in.
The third part (2 in this case) is the column index of the queried range from which the value should be read.
The last boolean tells whether or not it is a range lookup (in this case we're after a single value).

With your sample data:
Formula in cell B10:
=IFERROR(INDEX($A$1:$A$7,SMALL(IF($B$1:$B$7=$A10,ROW($A$1:$A$7),""),COLUMN(A1))),"")
Confirm through CtrlShiftEnter
Drag down and right...

Related

Ranking Duplicate String Values in Excel

I have a spreadsheet with string values and need to create a column with the rank (without using the rank function) of the duplicate values from another column.
Please see below for example of the desired outcome where Dupe_Rank is the created column.
Thanks!
Name
Dupe_Rank
John
1
John
2
Dave
1
John
3
Bill
1
Dave
2
let's say "Name" starts from column 'A' and row 2 as in below figure:
then add this formula:
=COUNTIF(A$2:A2,A2)
to cells below Dupe_Rank and then drag(or copy-paste) this formula to all the cells

How to extract unique values from one column based on criteria from two other columns, with or statement?

My data set looks something like this:
ID Name1 Name2
1 Jack Tom
1 Tom Tom
1 Lisa Tom
2 Tom
2 Tom
3 Frank Frank
3 John Frank
3 Frank Frank
3 John Frank
4 Tom
4 Tom
5 Lisa
5 Jack
and I want the following output:
Result
1
2
4
Note: I want the unique IDs for Tom if "Tom" shows in one of the two name columns.
I tried to use the following formula:
IFERROR(INDEX(INDIRECT($B$14); MATCH(0; IF($B$10=INDIRECT($B$16); IF($B$10=INDIRECT($B$15); COUNTIF($E$27:E27; INDIRECT($B$14)); "")); 0));"")
The problem is that this only gives me ID nr 1 as output since Tom shows up in both columns in this case. I think I need to implement an OR-statement to the formula.
Explanation of my formula:
Indirect(B14): array for the call IDs. B14 contains a name of this array.
B10: Contains the name I want to match (i.e. "Tom")
Indirect(B16): column Name1
Indirect(B15): column Name2
Good answers will be rewarded:)
I used your formula (without INDIRECT statements) and added ISNUMBER & FIND in order to find "Tom" in a combination of columns B and C:
This is an array formula (Ctrl+Shift+Enter):
=IFERROR(INDEX($A$1:$A$14,MATCH(0,COUNTIF($F$1:F1,IF(ISNUMBER(FIND("Tom",$B$1:$B$14&$C$1:$C$14)),$A$1:$A$14,"")),0)),"")
Result:
I couldn't use INDIRECT references as I'm not sure what exactly they point to (i.e. what are the ranges & column names). I hope it won't be too difficult for you to modify my formula in order to match your references.
Hope it helps! Cheers.

Excel find last match from two tables

I'm looking for a way to find the last instance on an entry in the columns A,B and get the corresponding values from columns C,D
In the example below value for Henry is 1374 and value for Amy is 1124
Name1 corresponds to Value1 and Name2 corresponds to Value2.
Is there a formula to find the last entry from both columns Name1 and Name2 and return the corresponding Value1 or Value2
Raw data pasted below:
Name1 Name2 Value1 Value2
Sara Amy 1265 1241
John Sara 1142 1214
Amy Henry 1295 1121
Amy John 1175 1323
Sara John 1085 1251
Sara Henry 1242 1374
Amy Sara 1124 1055
Slightly shorter:
= INDEX($C$1:$D$8,MAX(IF($A$1:$B$8=A10,ROW($A$1:$B$8))),MATCH(A10,
INDEX($A$1:$B$8,MAX(IF($A$1:$B$8=A10,ROW($A$1:$B$8))),0),0))
Note this is an array formula, so you must press Ctrl+Shift+Enter rather than just Enter after typing the formula.
See below for working example.
Assumptions:
Data Grid is in cells A1:D8.
Values "Henry" & "Amy" are in cell A10 & A11 respectively.
Formula implementation:
In cell B10 following formula is implemented.
Alternative 1:
=INDEX($C$2:$D$8,MAX(IFERROR(LOOKUP(2,1/($A$2:$A$8=A10),ROW($A$2:$A$8)),-1),IFERROR(LOOKUP(2,1/($B$2:$B$8=A10),ROW($B$2:$B$8)),-1))-1,IF(IFERROR(LOOKUP(2,1/($A$2:$A$8=A10),ROW($A$2:$A$8)),-1)>IFERROR(LOOKUP(2,1/($B$2:$B$8=A10),ROW($B$2:$B$8)),-1),1,2))
Alternative 2 (slightly shorter than 1):
=INDEX($C$2:$D$8,LOOKUP(2,1/SEARCH(A10&",",$A$2:$A$8&","&$B$2:$B$8&",",1),ROW($A$2:$A$8))-1,IF(IFERROR(LOOKUP(2,1/($A$2:$A$8=A10),ROW($A$2:$A$8)),-1)>IFERROR(LOOKUP(2,1/($B$2:$B$8=A10),ROW($B$2:$B$8)),-1),1,2)).
To be copied down as much needed.
Notice -1 value after MAX() function which is used to adjust row number. It should be always n-1 considering data starts at nth row.
I've been trying to remember another method I've seen for 2d lookup (I can't find the link any more). It's basically like this
=INDIRECT(TEXT(MAX((ROW($A$2:$B$8)*100+COLUMN($A$2:$B$8))*($A$2:$B$8=A10))+2,"R0C00"),FALSE)
entered as an array formula using CtrlShiftEnter.
So the idea is that you generate a number from the row and column where the last occurrence of the name is located (so for Henry it would be 702).
The you format it to give R7C02 and feed this in to an indirect to give the reference to the cell in RC notation. The column plus 2 gives the cell that you want.
You might notice that this would fail if column>99, but you can make the multiplier as big as you want.

Rename duplicates with random alphabets in a column - Excel

I have a list of 500 names in column A.
1 name1
2 name2
3 name3
4 name1
5 name2
6 name3
7 name1
8 name2
9 name3
..
And i need to add a prefix or suffix alphabets to the duplicates. And I should get
1 name1
2 a.name1
3 b.name1
4 name2
5 a.name2
6 b.name2
7 name3
8 a.name3
9 b.name3
..
And i have selected duplicate values
select column -> conditional formatting -> Highlight Cell Rules -> Duplicate Values
How to rename duplicate values with random alphabets prefix or suffix
If you prefer to use a non-random prefix that just contains the next letter, you could do something like this starting in C2:-
=IF(B2=B1,CHAR(96+COUNTIF(B$1:B1,B2))&"."&B1,B2)
I'm assuming that the names are sorted, have a heading and are in column B.
If you didn't want to sort them, this would still work with a modification:-
=IF(COUNTIF(A$1:A1,A2)>0,CHAR(96+COUNTIF(A$1:A1,A2))&"."&A2,A2)
I'm assuming that the unsorted names are in column A, with a header.
Without using VBA - you can't edit the cells themselves, except using formatting.
You could however, use a helper column and use a formula on these lines to accomplish this:
=IF(A2=A1,CHOOSE(RANDBETWEEN(1,26),"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")&" "&A2,A2)
Bear in mind that because this is random, there is a small chance of two consecutive letters - so you may need to use another formula to check for this and make a small amount of manual tweaks.

INDEX MATCH obtaining values for duplicate names

I have one example table with the following data in Sheet1 with the following random data
------A ----------------- B ----------------------C ------------------------D
1 --First--------------Last-----------------Start Date--------------End Date
2 --John--------------Smith--------------08/08/2014------------01/01/2015
3---John--------------Smith--------------08/11/2014------------17/11/2014
4---John--------------Smith--------------06/06/2014------------23/12/2014
5---Abel--------------Jones--------------14/05/2014------------29/04/2015
6---Abel--------------Jones--------------04/07/2014------------26/04/2015
Then I have another table in Sheet2
------A ----------------- B ----------------------C ------------------------D
1 --First--------------Last-----------------Start Date--------------End Date
2 --John--------------Smith---------------------------------------------------
3---John--------------Smith---------------------------------------------------
4---John--------------Smith---------------------------------------------------
5---Abel--------------Jones---------------------------------------------------
6---Abel--------------Jones---------------------------------------------------
I am using INDEX MATCH to transfer the data between the two sheets.
=INDEX(Sheet1!$C:$C,
MATCH(1,INDEX((Sheet1!$A:$A=$A3)*(Sheet1!$B:$B=$B3),0),0))
To populate column C with the start dates from Sheet1.
=INDEX(Sheet1!$D:$D,
MATCH(1,INDEX((Sheet1!$A:$A=$A3)*(Sheet1!$B:$B=$B3),0),0))
and this to populate column D with the end dates.
The problem is, when I perform this INDEX MATCH function, for a duplicate name, it will only copy over the first value. So this formula will paste 08/08/2014 into all 'John Smith' Start dates in column C of Sheet2.
How do I obtain all values so that C2 should be 08/08/2014, C3 should be 08/11/2014, C4 should be 06/06/2014 etc.
One solution would be to insert a column in both sheets with a "running count" of instances of the same name. For example, insert col C and in C2 enter =IF(A2&B2 = A1&B1, C1+1, 1). This starts the count at 1 if the concatenated first and last name is new, and increases the previous count by 1 if not. So you would have
First Last Count by Person
John Smith 1
John Smith 2
John Smith 3
Abel Jones 1
Abel Jones 2
George Washington 1
Thomas Jefferson 1
Thomas Jefferson 2
You can then add this column to your MATCH() function (and change the lookup column as necessary).
Edit: It is worth noting that this requires your raw data is sorted by name.
You can narrow the $A:$A refferances to something like $Ax+1:$Ay where y = last row of your excel sheet and x is position of previous occurance of this name/surname (you could store this in some dummy column).

Resources