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: 
zarmoton
Creator
Creator

calculation base on an interval join

Table : TT                            
TT_ID TT_START_DATE TT_END_DATE SITE_ID                      
1 01/07/2024 10/07/2024 A                      
1 01/07/2024 10/07/2024 B                      
1 01/07/2024 10/07/2024 C                      
2 05/07/2024 15/07/2024 A                      
2 05/07/2024 15/07/2024 D                      
                             
Table : TSR                            
FCT_DATE SITE_ID DWH_CALL_ID                        
28/06/2024 A 123                        
01/07/2024 A 234                        
05/07/2024 A 345                        
04/07/2027 D 456                        
02/07/2024 B 567                        
                             
                             
                             
How to right a script who calculate the column Nb CALL_ID, where the join is based on TT_ID and intervall on the date
                             
TT_ID TT_START_DATE TT_END_DATE SITE_ID Nb CALL_ID                    
1 01/07/2024 10/07/2024 A 2                    
1 01/07/2024 10/07/2024 B 1                    
1 01/07/2024 10/07/2024 C 0                    
2 05/07/2024 15/07/2024 A 1                    
2 05/07/2024 15/07/2024 D 0                    
Labels (1)
1 Reply
Vegar
MVP
MVP

You can use IntervalMatch with a keyfield (SITE_ID) . It would look something like the sample script below.

Vegar_0-1722847996896.png

 

SET DateFormat='DD/MM/YYYY'; //Ensuring date format identical to how it is in the source table.
TT:
LOAD * inline [
TT_ID, TT_START_DATE, TT_END_DATE, SITE_ID,
1, 01/07/2024, 10/07/2024, A,
1, 01/07/2024, 10/07/2024, B
1, 01/07/2024, 10/07/2024, C
2, 05/07/2024, 15/07/2024, A
2, 05/07/2024, 15/07/2024, D
];

TSR:
LOAD * inline [
FCT_DATE, SITE_ID, DWH_CALL_ID
28/06/2024, A, 123
01/07/2024, A, 234
05/07/2024, A, 345
04/07/2027, D, 456
02/07/2024, B, 567];

LEFT JOIN (TSR)
IntervalMatch (FCT_DATE, SITE_ID)
LOAD TT_START_DATE, TT_END_DATE, SITE_ID
RESIDENT TT;

LEFT JOIN (TT) LOAD * RESIDENT TSR;
DROP TABLE TSR;

 

(Note that the DWH_CALL_ID = 123 will get lost as it is not within a defined interval.)