Excel find duplicates in two tables and display related data - excel

Let's say I've got two tables with two columns. In both cases, the first column consists of a name and a second column consist string of characters with the similar pattern. It looks like this:
Table 1
Peter xxxxx01
John xxxxx01
Bill xxxxx01
William xxxxx01
Table 2
Richard xxxxx02
John xxxxx02
Bill xxxxx02
Arthur xxxxx02
Now, I'd like to compare these two tables, find values where the names are duplicated and display data stored in second columns, just like this:
(Peter excluded)
John xxxxx01 xxxxx02
Bill xxxxx01 xxxxx02
(William, Arthur excluded)
I am familiar with pivot tables, however, it won't allow doing this.
I've also tried messing with index match formulas but without much success.
Any advices?

You can use the VLOOKUP function for this.
If your "Table1" is in B3:C6, and your "Table 2" is in F3:G6, then you can use the following formula in D3:D6 to lookup the values in table 2;
Cell D3: =IFERROR(VLOOKUP(B3,$F$3:$G$6,2,FALSE),"")
This is first looking up the name in table 1 (Cell B3) against table 2 (F3:G6), and returning the second column of table 2 if it finds the name. If it doesn't find the name, it will return an error, so we wrap the VLOOKUP in an "IFERROR" function, and replace any errors with an empty string, so it looks a bit friendlier. This results in the following table;
A B C D E F G
1
2 Table 1 Result Table 2
3 Peter xxxxxx01 Richard xxxxxx02
4 John xxxxxx01 xxxxxx02 John xxxxxx02
5 Bill xxxxxx01 xxxxxx02 Bill xxxxxx02
6 William xxxxxx01 Arthur xxxxxx02
You can then filter on the (Non-Blanks) in column D to only get the results you're interested in.

Related

Google sheets formula to get the Top 5 List With Duplicates

I'm trying to compile a best 5 and worst 5 list. I have two rows, column B with the number score and column C with the name. I only want the list to include the name.
In my previous attempts the formula would get the top/bottom 5 but as soon as a duplicate score appeared the first known name with that value would just repeat.
Here is my data
26 Cal
55 John
55 Mike
100 Steve
26 Thomas
100 Jaden
100 Jack
95 Josh
87 Cole
75 Brett
I've managed to get the bottom 5 list formula correct. This formula works perfectly and includes all names of duplicate scores.
Example of what I get:
Cal
Thomas
John
Mike
Brett
=INDEX($C$56:$E$70,SMALL(IF($B$56:$B$70=SMALL($B$56:$B$70,ROWS(E$2:E2)),ROW($B$56:$B$70)-ROW($B$56)+1),SUM(IF($B$56:$B$70=SMALL($B$56:$B$70,
ROWS(E$2:E2)),1,0))-SUM(IF($B$56:$B$70<=SMALL($B$56:$B$70,ROWS(E$2:E2)),1,0))+ROWS(E$2:E2)))
Here is the formula I've tried to get the top 5 - however I keep getting an error.
=INDEX($C$56:$E$70,LARGE(IF($B$56:$B$70=LARGE($B$56:$B$70,ROWS(E$2:E2)),ROW($B$56:$B$70)-ROW($B$56)+1),SUM(IF($B$56:$B$70=LARGE($B$56:$B$70,
ROWS(E$2:E2)),1,0))-SUM(IF($B$56:$B$70<=LARGE($B$56:$B$70,ROWS(E$2:E2)),1,0))+ROWS(E$2:E2)))
Example of what I'm looking for
Steve
Jaden
Jack
Josh
Cole
You can set two queries like this for both cases:
=QUERY(B56:C70,"Select C order by B desc limit 5")
=QUERY(B56:C70,"Select C order by B limit 5")
Use SORTN() function like-
=SORTN(A1:B10,5,,1,1)
To keep only one column, wrap the SORTN() function with INDEX() and specify column number. Try-
=INDEX(SORTN(A1:B10,5,,1,1),,2)

Excel multi value counter

I couldn't find anything similar.
I have a pretty big excel table but I can't get what I need from it.
I have a column for example of names
John
Johnny
Arny
Arny
John
Johanatan
Jeremie
Brook
Arny
Johanatan
I want it to return or show me results like that
Johnny 1
Arny 3
John 1
Jeremie 1
Brook 1
Johanatan 2
Couldn't find an appropriate excel to result me with that.

Count X records matching certain conditions and only where there is a corresponding Y record

I am looking for some help with a formula. On my 'data' sheet, I have data in the format below:
A B C D E F G H I J
1 UID RecordType HCode AdmittedDate Forename Surname DOB Sex STDate RDate
2 87962 STAsses STIV1 01/01/2012 Mark Jones 13/07/1978 Male 09/12/2012
3 89658 Transfer GLSI2 01/01/2012 Alison Aitken 20/12/1956 Female 08/07/2013
4 84563 Discharge JHOP1 01/01/2012 David Beckham 09/08/1987 Male 08/07/2013
5 89654 STAsses STGE1 01/01/2012 Andrew Macbeth 27/09/1976 Male 08/07/2012
6 89867 Transfer KIND1 01/01/2012 George Deas 08/05/1989 Male 08/07/2013
7 87962 Transfer STIV1 01/01/2012 Mark Jones 13/07/1978 Male 04/03/2013
8 89654 Transfer STGE1 01/01/2012 Andrew Macbeth 27/09/1976 Male 12/08/2012
On my 'report' sheet, I have the following table set up:
B C D E F
4 HospCode RecordType Jul-12 Aug-12 Sep-12
5 STGE1 Assessments
6 Transfers
7 Discharges
8
What I need is a formula in cell D6 of the 'report' sheet, which counts all 'Transfer' records from the 'data' sheet, occurring in the month specified in D4 and with an 'HCode' matching that in B5 of the 'report' sheet. The tricky part is that I need this formula only to count records which have a corresponding 'STAssess' record.
Might be pushing the limits of Excel here, but anything is possible!
Thanks in advance.
You can simply use
=COUNTIFS(Sheet1!B1:B8, "Transfer", Sheet1!C1:C8, Sheet2!B5)
This is an example with 2 criteria, you can add a lot many more for multiple IFS and COUNTIFS will count those.
In case of finding multiple criteria across rows, you are better off making a Pivot Table out of this data range and then doing multiple selections thereof.
If you would like to accomplish this via formula, there is a two-step process.
THe formula described above needs to be placed next to each Person's name in Sheet1 as an additional column. And then run another COUNTIFS on this column and Column B counting that there is >1 Count for the person existing... and counting if the STAssess criterion is fulfilled or not.

Excel - Counting unique records in a group

I'm having difficulty counting records in a file that have a unique ID and listing the number of rows associated with that specific ID.
For this file, the unique ID represents a specific family (column A). Each member of the family is in a different row with the same ID. I would like to count the number of family members(rows) in each unique family. I can have a few thousand rows so automating this would be wonderful. Thanks for any help!!
You can do this now automatically with Excel 2013.
If you have that version, then select your data to create a pivot table, and when you create your table, make sure the option 'Add this data to the Data Model' tickbox is check (see below).
Then, when your pivot table opens, create your rows, columns and values normally. Then click the field you want to calculate the distinct count of and edit the Field Value Settings:
Finally, scroll down to the very last option and choose 'Distinct Count.'
This should update your pivot table values to show the data you're looking for.
So if I'm understanding you correctly, you have something like
A B C
Fam. ID LastName FirstName
1 Smith John
1 Smith Mary
1 Smith Johnnie Jr
2 Roe Rick
3 Doe Jane
3 Doe Sam
and you want a new column (say, D), with a count of members per family:
A B C D
Fam. ID LastName FirstName Fam. Cnt
1 Smith John 3
1 Smith Mary 3
1 Smith Johnnie Jr 3
2 Roe Rick 1
3 Doe Jane 2
3 Doe Sam 2
This will do it -- insert at D2 and drag down:
=COUNTIF(A:A,A2)

Count names one time (per year) regardless of how many there are by year

The problem is:
There is a table that gets data added to it each month. I use this data for many different pivot tables and reports, so I am not able to modify it. The user has requested that if its possible (and I assured him that it was) he would like to see two (2) single values of This Year and Last Year Doctors on the list.
The data looks something like this:
Doctor, In/Out, Date, Number
John Deaux Out 10/1/11 8
John Deaux Out 11/1/11 3
John Deaux Out 01/1/12 5
John Deaux Out 05/1/12 3
John Deaux Out 09/1/12 1
Billy White In 02/1/12 2
Mike Adams Out 06/1/11 6
Mike Adams Out 10/1/11 9
Mike Adams Out 01/1/12 1
Mike Adams Out 04/1/12 6
I would have 1 John Deaux for 2011, and 1 for 2012. The same for Mike Adams.
TY 2
LY 2
Now I only have to count the "Out"(s), so I have to be careful of that. Also, there is the chance that I would have to build this for the previous 12 months as well making it that much harder.
1 for John Deaux for the previous 12 months.
TY 2
LY 1
*TY: This Year - LY: Last Year
To do this manually:
Since you can't make any edits to the existing table, copy everything to a new table.
In the new table, add a column called Year. Use the Year() function to get the year out of the date cell.
Make another column called Count. Use If(A2="Out",1,0) where A2 is the cell in the In/Out column.
Copy the Doctor, Year, and Count columns to a new table.
Excel 2007 and above has a convenient tool called Remove Duplicates in the Data ribbon. Use that to remove the duplicates. This will keep you from counting a single doctor twice in the same year.
Create a pivot table, using Doctor as the row, Year as the column, and sum(count) for the value.
Check this, this will check the B column for the year 2012/2013 and count the distinct unique values in column A.
=SUM(IF(FREQUENCY(IF(YEAR(B1:B11)=2013;A1:A11);A1:A11)>0;1)) + CONTROL + SHIFT + ENTER
=SUM(IF(FREQUENCY(IF(YEAR(B1:B11)=2012;A1:A11);A1:A11)>0;1)) + CONTROL + SHIFT + ENTER

Resources