Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to associate a record to one of many matching records?

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 IDID/InstanceCourseStart dateEnd date
ABCABC/1BSc Mathematics1/8/200031/7/2003
ABCABC/2MSc Mathematics1/8/200331/7/2004
ABCABC/3PhD Mathematics1/8/200431/7/2007

APPOINTMENT:

Appointment IDAppointment DateStudent ID
11/1/2002ABC
21/1/2005ABC

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 IDAppointment DateStudent IDStudent ID/Instance
11/1/2002ABCABC/1
21/1/2005ABCABC/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 IDAppointment DateStudent IDStudent ID/Instance
11/1/2002ABCABC/1
11/1/2002ABCABC/2
11/1/2002ABCABC/3
21/1/2005ABCABC/1
21/1/2005ABCABC/2
21/1/2005ABCABC/3

How would I do this in QlikView?

Thanks.

13 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

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!

alexpanjhc
Specialist
Specialist

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;

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Almost there, Alex. You need to include Student ID in the Interval Match, in order to link each Student to his/her individual appointments.

alexpanjhc
Specialist
Specialist

Oleg-- it would not do the trick. Not sure why...

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

IntervalMatch( [Appointment Date], StudentID )

LOAD

     StudentID,

     [Start date],

     [End date]

Resident table1;

This should work

alexpanjhc
Specialist
Specialist

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;

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

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...

Not applicable
Author

Thanks Oleg and Alex,

Unfortunately I still can't get this to work. Using the code below I still get the following table:

Appointment IDAppointment DateStudent IDID/Instance
11/1/2002ABCABC/1
11/1/2002ABCABC/2
11/1/2002ABCABC/3
21/1/2005ABCABC/1
21/1/2005ABCABC/2
21/1/2005ABCABC/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;

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

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#()