This is a type of problem that you may prefer to solve with SQL than in the QlikView script. Are you sure you cannot use SQL? There are drivers both for text files and for Excel files.
Anyway - if I was to do it in the QlikView script, I would do something along the lines of:
// === All appointments
RecNo() as TempAppointmentID
From Appointments ;
// === Just follow up appointments
AppointmentDate as FollowUpDate
where AppointmentType = 'Followup';
// === All appointments again
TempAppointmentID as AppointmentID,
If(FollowUpDate - AppointmentDate > 0 and FollowUpDate - AppointmentDate <= 90, 'Yes', 'No') as HasFollowUp
Where ( FollowUpDate - AppointmentDate > 0 or IsNull(FollowUpDate) )
and not Exists(AppointmentID,TempAppointmentID) // To get only one record per appointment
Order By AppointmentDate, FollowUpDate;
Drop Table TempAppointments;
Thank you VERY much Henric, I was having a brain fade and your responce got me back on track. The use of the exists clause was particularly helpful.
As an aside I could not use SQL as I using an Object Orientated Database and the ODBC connector is very basic, with limited functionality, (pretty much select and group).