Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
beunderf
Partner - Creator II
Partner - Creator II

A Join with conditions

Hello everybody,

I have a question. I want to join data between tables using some conditions or rules.

I have two tables. One table gives me the schedule of a bus:

Table A:

CarIDStation sequenceDirectionStationDeparture time
1001SouthAmsterdam9:45:00
1002SouthUtrecht9:57:00
1003SouthVeenendaal10:14:00
1004SouthArnhem10:29:00
1005SouthNijmegen10:40:00
2001SouthAmsterdam9:55:00
2002SouthUtrecht10:07:00
2003SouthVeenendaal10:24:00
2004SouthArnhem10:39:00
2005SouthNijmegen10:50:00
3001NorthNijmegen9:45:00
3002NorthArnhem9:57:00
3003NorthVeenendaal10:14:00
3004NorthUtrecht10:29:00
3005NorthAmsterdam10:40:00

The other gives me chekin and checkout times and station of a passanger:

Table B:

TransactionIDcheckincheckoutcheckin stationchekout station
19:55:0010:31:00UtrechtArnhem
29:56:0010:31:00UtrechtArnhem
39:57:0010:33:00UtrechtArnhem
410:03:0010:42:00UtrechtArnhem
510:04:0010:43:00UtrechtArnhem
610:05:0010:45:00UtrechtArnhem

Now I want to join these to tables so that I now in which bus the passenger took. Expected result:

TransactionIDcheckincheckoutcheckin stationchekout stationUsed CarID
19:55:0010:31:00UtrechtArnhem100
210:05:0010:45:00UtrechtArnhem200
39:56:0010:31:00UtrechtArnhem100
49:57:0010:33:00UtrechtArnhem100
510:04:0010:43:00UtrechtArnhem200
610:03:0010:42:00UtrechtArnhem200

Extra info for the join:

Checkin time <= departure time

Checkout time => departure time of checkout station

The checkin station has a lower Station Sequence number as the Checkout station.

Does anyone know how to achieve this with Qlikview scripting. At this point, I have no idea, because I believe it not possible to compare fields of table A en Table B before or when the join is made? Who can help me?

I added a Qlikview file with the data

Best regards,

Frank

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You weren't matching beacuse I forgot to tell you that [checkin station] had to be called Station for the match.

There was still a problem where a  [Departure Time] matches too many trains, but I added some min logic following to get keep only the first match. Hopefully this will move you forward.

-Rob

INNER JOIN (Transactions)

IntervalMatch([Departure time], Station) LOAD checkin, checkout, [checkin station] as Station RESIDENT Transactions;

INNER JOIN (Transactions)

LOAD

          TransactionID,

          min([Departure time]) as [Departure time]

RESIDENT Transactions

GROUP BY TransactionID

;

View solution in original post

14 Replies
SunilChauhan
Champion II
Champion II

see the attached

hope this helps

Sunil Chauhan
beunderf
Partner - Creator II
Partner - Creator II
Author

Dear Sunil,

Thanks for your input, but is not what I am looking for. One TransactionID should be joined to only one CarID depending on the Checkin/chekout time and station. Your join is just simply on checkin station.

The exact result after the join should be the folowing table:

TransactionIDcheckincheckoutcheckin stationchekout stationUsed CarID
19:55:0010:31:00UtrechtArnhem100
210:05:0010:45:00UtrechtArnhem200
39:56:0010:31:00UtrechtArnhem100
49:57:0010:33:00UtrechtArnhem100
510:04:0010:43:00UtrechtArnhem200
610:03:0010:42:00UtrechtArnhem200
SunilChauhan
Champion II
Champion II

sorry  Frank,

I believe soe thing you need to check,

i think there should be Cardir or transactionid common in both table

or something else

or someone helps

Sunil Chauhan
rohit214
Creator III
Creator III

Hey frank,

I attached modified your application,

Please chaek it out

i know the way i did may be not correct,

thanks and regard

rohit

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think for this problem you want "Extended Interval Match". Take a look in the Ref Guide for details.

-Rob

http://robwunderlich.com

beunderf
Partner - Creator II
Partner - Creator II
Author

Hi Rohit,

Thanks for your response. You hardcoded the result in a Expression 🙂

That gives the correct anwser indeed, but that is not what I am looking for.

I am looking for a way to dynamicly find the correct anwser.

Frank

beunderf
Partner - Creator II
Partner - Creator II
Author

Hi Rob,

Thanks for your anwser!

I know how the 'normal' intervalmatch works. Now I am looking at the Extended syntax, but I don't get it yet.

I will try to find more information about it, but if you have some examples, feel free to share them with me 😉

Best Regards,

Frank

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I have some questions on the data. In your expected results, you show that Tran 2 took CarID 200. But it seems to me that with the Table B of 9:56 they would take CarID 100. Also in the Result table the checkin/checkout times for Tran 2 have changed, as they have for other Trans. It seems to me those values shouldn't change. Can you confirm for me if this is typo or if I'm misunderstanding?

-Rob

beunderf
Partner - Creator II
Partner - Creator II
Author

Hi Rob,

You are completly right, I did some sorting in Excel before I posted tmy example informtation, but I forgot to sort the result table. This is result I expect:

TransactionIDcheckincheckoutcheckin stationchekout stationUsed CarID
19:55:0010:31:00UtrechtArnhem100
29:56:0010:31:00UtrechtArnhem100
39:57:0010:33:00UtrechtArnhem100
410:03:0010:42:00UtrechtArnhem200
510:04:0010:43:00UtrechtArnhem200
610:05:0010:45:00UtrechtArnhem200

Sorry about my error, this makes it a bit more logical 🙂