Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a situation where I'm trying to select one record out of many based on the date of an appointment.
I have for example the following two tables (in csv files) involving students having appointments. The first contains data about the student, the second about the appointment:
STUDENT:
Student ID | ID/Instance | Course | Start date | End date |
---|---|---|---|---|
ABC | ABC/1 | BSc Mathematics | 1/8/2000 | 31/7/2003 |
ABC | ABC/2 | MSc Mathematics | 1/8/2003 | 31/7/2004 |
ABC | ABC/3 | PhD Mathematics | 1/8/2004 | 31/7/2007 |
APPOINTMENT:
Appointment ID | Appointment Date | Student ID |
---|---|---|
1 | 1/1/2002 | ABC |
2 | 1/1/2005 | ABC |
What I need to do is find a way to connect the Appointment ID to the most appropriate ID/Instance based on the date of the appointment. I.e. Appointment 1 took place while Student ABC was studying the BSC Mathematics, while Appointment 2 took place while ABC was studying the PhD Mathematics.
So I want a table like this:
APPOINTMENT:
Appointment ID | Appointment Date | Student ID | Student ID/Instance |
---|---|---|---|
1 | 1/1/2002 | ABC | ABC/1 |
2 | 1/1/2005 | ABC | ABC/3 |
This would enable me to analyse appointment data based on the circumstances of the student at the time of the appointment. A simple association based on Student ID however gives me something like this:
Appointment ID | Appointment Date | Student ID | Student ID/Instance |
---|---|---|---|
1 | 1/1/2002 | ABC | ABC/1 |
1 | 1/1/2002 | ABC | ABC/2 |
1 | 1/1/2002 | ABC | ABC/3 |
2 | 1/1/2005 | ABC | ABC/1 |
2 | 1/1/2005 | ABC | ABC/2 |
2 | 1/1/2005 | ABC | ABC/3 |
How would I do this in QlikView?
Thanks.
Looks like you need to use the IntervalMatch link, in its extended syntax (including the Student ID in the match.
cheers,
Oleg Troyansky
Upgrade your Qlik skills at the Masters Summit for Qlik - coming soon to Milan, Italy!
try this:
table1:
LOAD //[Student ID],
[ID/Instance],
//Course,
[Start date],
[End date]
FROM
[https://community.qlik.com/thread/205698]
(html, codepage is 1252, embedded labels, table is @1);
table2:
LOAD [Appointment ID],
[Appointment Date],
[Student ID]
FROM
[https://community.qlik.com/thread/205698]
(html, codepage is 1252, embedded labels, table is @2);
IntervalMatch( [Appointment Date] )
LOAD
[Start date],
[End date]
Resident table1;
Almost there, Alex. You need to include Student ID in the Interval Match, in order to link each Student to his/her individual appointments.
Oleg-- it would not do the trick. Not sure why...
IntervalMatch( [Appointment Date], StudentID )
LOAD
StudentID,
[Start date],
[End date]
Resident table1;
This should work
Oleg,
I may miss something but it is just not working for me?
table1:
LOAD [Student ID],
[ID/Instance],
Course,
[Start date],
[End date]
FROM
[https://community.qlik.com/thread/205698]
(html, codepage is 1252, embedded labels, table is @1);
table2:
LOAD [Student ID],
[Appointment ID],
[Appointment Date]
FROM
[https://community.qlik.com/thread/205698]
(html, codepage is 1252, embedded labels, table is @2);
IntervalMatch( [Appointment Date], [Student ID] )
LOAD [Student ID],
[Start date],
[End date]
Resident table1;
IntervalMatch( [Appointment Date], [Student ID] )
LOAD
[Start date],
[End date],
[Student ID]
Resident table1;
The order of fields matters in this case, sorry for the earlier confusion...
Thanks Oleg and Alex,
Unfortunately I still can't get this to work. Using the code below I still get the following table:
Appointment ID | Appointment Date | Student ID | ID/Instance |
---|---|---|---|
1 | 1/1/2002 | ABC | ABC/1 |
1 | 1/1/2002 | ABC | ABC/2 |
1 | 1/1/2002 | ABC | ABC/3 |
2 | 1/1/2005 | ABC | ABC/1 |
2 | 1/1/2005 | ABC | ABC/2 |
2 | 1/1/2005 | ABC | ABC/3 |
The table view also looks quite messy.
Student:
LOAD [Student ID],
[ID/Instance],
[Course],
[Start date],
[End date]
FROM [https://community.qlik.com/thread/205698]
(html, codepage is 1252, embedded labels, table is @1);
Appointment:
LOAD [Student ID],
[Appointment ID],
[Appointment Date]
FROM [https://community.qlik.com/thread/205698]
(html, codepage is 1252, embedded labels, table is @2);
IntervalMatch([Appointment Date],[Student ID])
LOAD [Start date],
[End date],
[Student ID]
Resident Student;
The field End Date is not being loaded as a date, possibly because of its DD/MM/YYYY format - at least, this is how it looks on my end.
In order to troubleshoot the logic, verify that all dates are being properly formatted as date fields - not strings. You may have to force them into the data format using the function date#()