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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
adrianfer
Contributor III
Contributor III

Help with joining two tables

Hi, I need help joining these two resident tables - EMPLOYEE and LOCATION. 

EMPLOYEE

EmployeeIdReferenceDate
1111/8/19
1112/8/19
1113/8/19
1114/8/19
1115/8/19
2221/8/19
2222/8/19
2223/8/19
2224/8/19
2225/8/19

 

LOCATION

EmployeeIdStartDateEndDateLocation
1112/8/193/8/19AAA
1114/8/195/8/19BBB
2221/8/194/8/19AAA

 

The resulting table should be like this - it will have the same rows as the EMPLOYEE table plus 2 additional columns:

In_AAA = value will be 1 if Location is AAA and if the EMPLOYEE.ReferenceDate is between the LOCATION.StartDate and LOCATION.EndDate

In_BBB = value will be 1 if Location is BBB and if the ReferenceDate is between the LOCATION.StartDate and LOCATION.EndDate

EmployeeIdReferenceDateIn_AAAIn_BBB
1111/8/1900
1112/8/1910
1113/8/1910
1114/8/1901
1115/8/1901
2221/8/1910
2222/8/1910
2223/8/1910
2224/8/1910
2225/8/1900

 

Thank you in advance!

Labels (1)
1 Solution

Accepted Solutions
lironbaram
Partner - Master III
Partner - Master III

hi

this script will give you what you look for 

[Table]:
LOAD * INLINE
[
EmployeeId,ReferenceDate
111,1/8/19
111,2/8/19
111,3/8/19
111,4/8/19
111,5/8/19
222,1/8/19
222,2/8/19
222,3/8/19
222,4/8/19
222,5/8/19
](delimiter is ',');

[Table2]:
LOAD
[EmployeeId] ,
date([StartDate]+iterno()-1) as ReferenceDate,
[Location]
while date([StartDate]+iterno()-1)<=[EndDate];
LOAD * INLINE
[
EmployeeId,StartDate,EndDate,Location
111,2/8/19,3/8/19,AAA
111,4/8/19,5/8/19,BBB
222,1/8/19,4/8/19,AAA
](delimiter is ',');


//////////////////add location to table ///////
left join ([Table])
load [EmployeeId],
ReferenceDate,
[Location]
Resident [Table2];

drop Table Table2;
/////////////calculating ne fields /////////////
TableFinal:
load *,
if([Location]='AAA',1,0) as In_AAA,
if([Location]='BBB',1,0) as In_BBB
resident Table;

drop Table Table;

View solution in original post

2 Replies
lironbaram
Partner - Master III
Partner - Master III

hi

this script will give you what you look for 

[Table]:
LOAD * INLINE
[
EmployeeId,ReferenceDate
111,1/8/19
111,2/8/19
111,3/8/19
111,4/8/19
111,5/8/19
222,1/8/19
222,2/8/19
222,3/8/19
222,4/8/19
222,5/8/19
](delimiter is ',');

[Table2]:
LOAD
[EmployeeId] ,
date([StartDate]+iterno()-1) as ReferenceDate,
[Location]
while date([StartDate]+iterno()-1)<=[EndDate];
LOAD * INLINE
[
EmployeeId,StartDate,EndDate,Location
111,2/8/19,3/8/19,AAA
111,4/8/19,5/8/19,BBB
222,1/8/19,4/8/19,AAA
](delimiter is ',');


//////////////////add location to table ///////
left join ([Table])
load [EmployeeId],
ReferenceDate,
[Location]
Resident [Table2];

drop Table Table2;
/////////////calculating ne fields /////////////
TableFinal:
load *,
if([Location]='AAA',1,0) as In_AAA,
if([Location]='BBB',1,0) as In_BBB
resident Table;

drop Table Table;

adrianfer
Contributor III
Contributor III
Author

Thank you! that worked perfectly!