Merging Excel sheets by categories - excel

I want to attach categories from a different dataset to another dataset using Excel if that makes any sense. For example, I am given a dataset:
Column A
Column B
0
Happy
1
Sad
2
Angry
And dataset:
Column A
Column B
Column C
John
0
today
Bob
1
tomorrow
Ron
2
yesterday
Sally
1
yesterday
Amy
2
today
Lin
0
yesterday
I want the data to end up looking like this:
Column A
Column B
Column C
Column D
John
0
today
Happy
Bob
1
tomorrow
Sad
Ron
2
yesterday
Angry
Sally
1
yesterday
Sad
Amy
2
today
Angry
Lin
0
yesterday
Happy
I was told to use a VLookUp formula to make it happen, but every single time that I try, I get NA values, and I have no idea how to approach the problem. I am also somewhat new to Excel.

=VLOOKUP(B2, sheet1!$A$1:$B$4, 2, FALSE) drop it in D2 and drag down. Without $ it moves range you are looking at when dragging
Or you can lookup for whole array:
=VLOOKUP(B2:B7, sheet1!$A$1:$B$4, 2, FALSE)

Related

Distributing students across classes based on marks

Name
Marks
Rank
Class
Eddie
20
6
C
Tom
10
10
A
Jenny
30
4
A
Riva
40
3
C
Andy
50
2
B
Mark
5
11
B
Sally
78
1
A
Jack
15
8
B
Dick
15
8
C
Harry
20
6
A
Dom
30
4
B
The students are expected to be distributed across classes A, B and C, based on their marks in the above picture.
The student with the highest marks goes in A. The one with the next highest goes in B. The next highest goes in C. The next goes again to A and so on.
What should be the formula to be used in Excel 2013 and above for calculating the Class?
Sort the table by either Marks descending or Rank ascending.
D2: =CHOOSE(MOD(ROWS($1:1)-1,3)+1,"A","B","C")
If you are using Excel 365, you can use the SORTBY function to solve the question.
Assume the Name column is in a named range called List_Name, the Marks column is in a named range called List_Marks, your example dataset is in range A1:D12, and you want to return the class code in column D.
In cell D2, enter any one of the following formulas and drag it down:
=CHOOSE(MOD(MATCH(A2,SORTBY(List_Name,List_Marks,-1),0),3)+1,"C","A","B")
Alternatively, you can use the following in cell D2 instead:
=INDEX({"C";"A";"B"},MOD(MATCH(A2,SORTBY(List_Name,List_Marks,-1),0),3)+1)
If you cannot use the SORTBY function, then the answer provided by Ron Rosenfeld should do the job quite well.
Let me know if you have any questions.
Assuming that the chart you provided is in cells A1-D11
Try making a 2x3 chart on the side (I’m using F2-G4 with 1...A 2...B 0...C
and then put the formula in D1 as follows: =vlookup(mod(C2,3),F2:G4, false)
You could even skip out the whole C column if you wanted, writing =vlookup(mod(rank(A2,B:B),3),F2:G4, false)
But then you might have an issue of 2 people going to the same class if they rank the same.

Excel count rows where column B equals value and value in column A is not a duplicate

I have a table as follows:
A
B
1
happy
1
sad
2
angry
2
sad
3
sad
4
moody
4
thoughtful
5
excited
I need to count the number of times "sad" appears in column B whose value in column A is NOT a duplicate.
I am aware of =COUNTIF(B2:B8, "sad") but I'm stuck there.
Our answer should be 1 since sad only occurs once without a duplicate in A.
Thank you.
Use SuMPRODUCT with a COUNTIFS():
=SUMPRODUCT((B1:B8="Sad")*(COUNTIF(A1:A8,A1:A8)=1))

COUNTIF/MATCH after date

What I'm essentially looking to do is be able to track to see how many refills our patients have received. I have a list of what was sent to the pharmacy, and what the pharmacy has returned. What I would like to do is fill in Column C on Sheet 1, which will track if the patient received any refills after their initial prescription fill. As below, patients can get more than one prescription in any month for different drugs. All I'm looking to do is count how many months they received something after their first month's fill.
In this example, Patient John would have 2 months of refills, Adam would have 0 (or No fills at all), Bob would have 0 refills, and Phil would have 1 refill month.
Thanks!
Sheet 1
A B C
Date Patient Refills
1/1/18 John
1/2/18 Adam
1/3/18 Bob
1/4/18 Phil
Sheet 2
A B C
Date Filled Patient Prescription
1/10/18 John Drug A
1/10/18 John Drug B
1/12/18 Bob Drug A
1/12/18 Bob Drug B
1/12/18 Bob Drug C
1/13/18 Phil Drug C
2/10/18 John Drug A
2/10/18 John Drug B
2/13/18 Phil Drug C
2/13/18 Phil Drug D
3/10/18 John Drug A
Well here are a couple of formulas which go some way towards addressing the problem.
The first one is just a standard formula for counting the number of different dates for John which can be pulled down for the other patients
=MAX(SUM(--(FREQUENCY(IF(B$2:B$12=F2,A$2:A$12),$A$2:$A$12)>0))-1,0)
The next one is counting the number of different months for John, and can also be pulled down for the other patients. In this case, two different dates for the same patient in the same month would be counted as one:
=MAX(SUM(--(FREQUENCY(IF(B$2:B$12=F2,MONTH(A$2:A$12)),MONTH($A$2:$A$12))>0))-1,0)
Both these have to be entered as array formulas using CtrlShiftEnter
I have changed the data slightly to show the difference between the two formulas
Note that these formulas have limitations as mentioned in the comment, where the prescription dates might split across the end of a month in your real data, or if they span multiple years, in which case you would need a more sophisticated approach.
on sheet1, column c2
=COUNTIFS(Sheet2!B:B,Sheet1!B2,Sheet2!A:A,">" & A2)

Merge data from two sheets into correct row

I have two excel sheets, with data similar to this:
SHEET 1:
A B C
1 Josh 30 Austin
2 Sam 28 SF
3 Mary 35 Chicago
SHEET 2:
A B
1 Josh Car
2 Mary Truck
3 Sam Van
What I'm attempting to do is merge the two based on Column A. For example, the outcome would be:
A B C D
1 Josh 30 Austin Car
2 Sam 28 SF Van
3 Mary 35 Chicago Truck
I've tried digging through the Excel support on Microsoft's site, but I'm not getting anywhere. Originally I thought it would have something to do with the Data > Consolidate feature, but that doesn't seem to be working.
With the assumption that your names are unique in Sheet2,
On Sheet1 Cell D1 enter:
=Vlookup(a1,Sheet2!a:b,2,0)
And drag it until the end of your data.

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