Hi All,
I have a very complicated (for me) query. I am working on a blood sugar calculations and have the following under Screening Type: FBS, PPBS, HgA1C. A patient can have any of the 3 screenings. Here is how my query is setup:
PatientID--ScreeningType--DateofVisit--Result--Outcome--MaxDOV--DayCount
1234--FBS--01/20/2011--100--Controlled--01/20/2011--179
1234--PPBS--02/20/2011--130--Uncontrolled--02/20/2011--148
1234--HgA1C--02/04/2011--7--Uncontrolled--02/04/2011--164
This is where it gets tricky, I want to get the latest outcome of the 3, in this case it's PPBS so outcome should be Uncontrolled. However, if HgA1C is within 3 months of the other readings, then get HgA1C outcome which is Uncontrolled. I was able to do this in Excel but am having a hard time in access.
I added 2 more columns:
MaxDOV - Patients will have several readings but I only wanted to get the latest from each ScreeningType. This is the latest date for the individual screening
DayCount - To try to get which has the latest date, I calculated todays date - MaxDOV.
So what I am trying to do is to get a query like below if HgA1c is "within 3 months of any of the readings:
PatientID--ScreeningType--DateofVisit--Result--Outcome--MaxDOV--DayCount
1234--HgA1C--02/04/2011--7--Uncontrolled--02/04/2011--164
If HgA1c is not within 3 months, let's say it's date is 09/04/2010, then get the latest outcome for the patient. Which is:
PatientID--ScreeningType--DateofVisit--Result--Outcome--MaxDOV--DayCount
1234--PPBS--02/20/2011--130--Uncontrolled--02/20/2011--148
I hope this is possible, I have been pulling my hair on this for a few days.
Thank you very much.
John
I have a very complicated (for me) query. I am working on a blood sugar calculations and have the following under Screening Type: FBS, PPBS, HgA1C. A patient can have any of the 3 screenings. Here is how my query is setup:
PatientID--ScreeningType--DateofVisit--Result--Outcome--MaxDOV--DayCount
1234--FBS--01/20/2011--100--Controlled--01/20/2011--179
1234--PPBS--02/20/2011--130--Uncontrolled--02/20/2011--148
1234--HgA1C--02/04/2011--7--Uncontrolled--02/04/2011--164
This is where it gets tricky, I want to get the latest outcome of the 3, in this case it's PPBS so outcome should be Uncontrolled. However, if HgA1C is within 3 months of the other readings, then get HgA1C outcome which is Uncontrolled. I was able to do this in Excel but am having a hard time in access.
I added 2 more columns:
MaxDOV - Patients will have several readings but I only wanted to get the latest from each ScreeningType. This is the latest date for the individual screening
DayCount - To try to get which has the latest date, I calculated todays date - MaxDOV.
So what I am trying to do is to get a query like below if HgA1c is "within 3 months of any of the readings:
PatientID--ScreeningType--DateofVisit--Result--Outcome--MaxDOV--DayCount
1234--HgA1C--02/04/2011--7--Uncontrolled--02/04/2011--164
If HgA1c is not within 3 months, let's say it's date is 09/04/2010, then get the latest outcome for the patient. Which is:
PatientID--ScreeningType--DateofVisit--Result--Outcome--MaxDOV--DayCount
1234--PPBS--02/20/2011--130--Uncontrolled--02/20/2011--148
I hope this is possible, I have been pulling my hair on this for a few days.
Thank you very much.
John