I have a query that is pulling a list of patients seen within a certain time frame at certain locations and it also shows whether they had a certain test done. I want to report by location the list of patients seen and whether the test was done or not.
So in my query I'm grouping by PatientID and PatientName, for my criteria I have a couple of where statements for LocationID and Date. To show if the test was done I have a field Max([test from data].[Value]) AS Result that another field looks at and gives a a value of 0 or 1 so I can sort the report off of IIf([Result] Is Null,0,1) AS TestSort. Last I have the name of the facility as Last(Facilities.Name) AS Facility
Now here's my problem, if a patient was seen at three different locations (say location 10, 11 & 12) but had the test done at location 11 then the result of the query lists location 12 for the facility. If I change the facility name to First(Facilities.Name) AS Facility then I get location 10 in the result.
I can't find the function that applies to the facility so that the result I get comes from the location the test was done at. I've tried the built in functions from the query drop down list on the total row like Max, Min, First, Last but am thinking I need an expression to get what I need.
Can someone help me out?