My query pulls records from a table based on a UserID, Priority (Yes/No), then assigns a review date based on an iif statement.
SELECT Roster.UserID,
EventLog.Priority,
IIf([EventLog]![Priority]=True, [EventLog]![Date], Date()-183) AS [Review Date]
FROM EventLog
INNER JOIN Roster
ON EventLog.UserID = Roster.UserID
GROUP BY Roster.UserID, EventLog.Priority,
IIf([EventLog]![Priority]=True, [EventLog]![Date], Date()-183);
As not every recory will have a priority (Yes) indicator, my query is returning both Yes and No options for those users that have a (Yes).
Query Results ex.
UserID Priority Review Date
abc123 Yes 5-19-2012
abc123 No 5-22-2012
qwe456 No 5-22-2012
yip552 Yes 3-10-2012
yip552 No 5-22-2012
How do I have it return only the Yes answer for those UserIDs that have one and keep the NO calculation for those that dont?
You should be able to use Max or Min, depending in the data stored, the word “Yes” will be Max, but the value -1 will be Min:
You should be able to choose Expression forIIf([EventLog]![Priority]=True, [EventLog]![Date], Date()-183) AS [Review Date], so it need not be included in GROUP BYYou can choose Max for the IIf statement, too.