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

Match Dates

Hi everyone!!  I have the following table

EmployeeDateCode
555510/10/2018H
555527/06/2018T
555523/06/2018H
555506/04/2018T
555503/03/2018H

 

This is an employee, H=Hire and T=Term, this is an employee that was hired 3 times and he left 2 times, so he is currently active, i want to match Date, i need to get the following 

EmployeeHireDateTermDate
555510/10/2018null/empty
555523/06/201827/06/2018
555503/03/201806/04/2018

 

Any ideas?

Thanks!

1 Solution

Accepted Solutions
sunny_talwar

Try something like this

Table:
LOAD * INLINE [
    Employee, Date, Code
    5555, 10/10/2018, H
    5555, 27/06/2018, T
    5555, 23/06/2018, H
    5555, 06/04/2018, T
    5555, 03/03/2018, H
];

TempTable:
LOAD *,
	 If(Employee = Previous(Employee), If(Code = 'T', Peek('Times'), RangeSum(Peek('Times'), 1)), 1) as Times
Resident Table
Order By Employee, Date;

DROP Table Table;

FinalTable:
LOAD Employee,
	 Times,
	 Date as HireDate
Resident TempTable
Where Code = 'H';

Left Join (FinalTable)
LOAD Employee,
	 Times,
	 Date as TermDate
Resident TempTable
Where Code = 'T';

DROP Table TempTable;

View solution in original post

4 Replies
sunny_talwar

This how you want the data to be stored in the backend or do you want to show this on the front end of the app?
dmoreno2605
Contributor III
Contributor III
Author

This is how i want it in the back
sunny_talwar

Try something like this

Table:
LOAD * INLINE [
    Employee, Date, Code
    5555, 10/10/2018, H
    5555, 27/06/2018, T
    5555, 23/06/2018, H
    5555, 06/04/2018, T
    5555, 03/03/2018, H
];

TempTable:
LOAD *,
	 If(Employee = Previous(Employee), If(Code = 'T', Peek('Times'), RangeSum(Peek('Times'), 1)), 1) as Times
Resident Table
Order By Employee, Date;

DROP Table Table;

FinalTable:
LOAD Employee,
	 Times,
	 Date as HireDate
Resident TempTable
Where Code = 'H';

Left Join (FinalTable)
LOAD Employee,
	 Times,
	 Date as TermDate
Resident TempTable
Where Code = 'T';

DROP Table TempTable;
dmoreno2605
Contributor III
Contributor III
Author

It totally did the job, thanks!!!