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)
Related
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)
I am creating a score sheet in which I would like to count how many times a person played in a specific month. The formula will be on a separate tab/sheet. The table of data will look similar to this:
Month Player1 Player2 Player3 Player4
January Bob Joe Ed John
January Joe Scott Bob Dan
January Dan John Ed Scott
February Bob Ed Joe Dan
February Dan John Ed Scott
February John Ed Bob Dan
I would like to count how many times Bob played in the month of January. This is the code I've tried and it counts only the first roll of my sheet. For example, I get the result of only "1" for Bob in the month of January.
=COUNTIF(INDEX(Scoreboard!$B$2:$H$282,MATCH(Scoreboard!$O2,ScoreBoard!$A$2:$A$282,0,),""&Names!R$5&"")
The "Names" tab will have all the players name and count the number of games played for the selected month. Cell "O2" is where I select which Month I want to see.
Any help will be appreciated!
With data in columns A through E, in G1 enter the month of interest. In H1 enter the name of interest. The in another cell enter:
=SUMPRODUCT(--(A1:A100=G1) * (B1:B100=H1))+SUMPRODUCT(--(A1:A100=G1) * (C1:C100=H1))+SUMPRODUCT(--(A1:A100=G1) * (D1:D100=H1))+SUMPRODUCT(--(A1:A100=G1) * (E1:E100=H1))
Alternatively, you could use a pivot table.
I have the following table:
1 John Doe
John Doe
2 Adam Smith
Adam Smith
Adam Smith
I need to count the number of times a name appears for each number value in column A. The numbers are unique.
Place this formula in cell C1 and drag down until the end.
=IF(ISNUMBER(A1),COUNTIF(B:B,B1),"")
n.b. - you can more clearly define row numbers instead of using B:B if you like as well
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).
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