Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
qlik_j
Contributor
Contributor

How to compare data with in the same column for different months?

Hi Experts, 

I need some help please. I am trying to compare the head count between year-end 2018 (December 2018) with Nov 2019 (Max year/month that I have uploaded). I created a sample table for reference.

MonthEmployee_IDEmploye_Name
Dec-181100Adam
Dec-181101Alex
Dec-181112David
Dec-181115John
Jan-191100Adam
Jan-191101Alex
Jan-191112David
etc.etc.etc.
etc.etc.etc.
etc.etc.etc.
etc.etc.etc.
Nov-191100Adam
Nov-191112David
Nov-191200Ken
Nov-191201Kevin
Nov-191202Sam

 

I would like to somehow compare or match Employee_ID for the two months. If Employee_ID appears in Dec-2018 and not in Nov-2019 that means its a Termination.  And if the Employee_ID appears in Nov-19 and not in Dec-18 it is an Addition. End goal is to get the count of Termination and Addition based on the above logic. So comparing the two months (dec 2018 and Nov 2019) we should get 3 additions (Employee_ID: 1200, 1201, 1202) and 2 terminations (Employee_ID: 1101,1115).

I will eventually put this in a waterfall. 

Can someone please help me with it. Thanks 🙂

Labels (1)
1 Reply
dwforest
Specialist II
Specialist II

This would be easiest in the load script. Something like:

[Emp Temp]:

LOAD

     Employee_ID, Month,Employee_Name,If(Previous(Employee_ID)=Employee_ID,If(isnull(Previous(Month),1) AS Addition;

 

LOAD

Employee_ID,Month,Employee_Name

FROM Table1

ORDER BY Employee_ID,Month;

 

[Emp]:

NoConcatenate

LOAD Employee_ID,Month,Employee_Name, Addition, If(Isnull(Previous(Month),1) AS Termination

RESIDENT [Emp Tem]

ORDER BY Employee_D, Month desc;