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

Adding Rows to Show Changes between to Year Periods

Hello I have a table of data (sample attached) that includes three elements - Employee ID, Department and Year_Period.  What I am looking to do is have a process that looks between the Year_Period and creates records that are categorized as noted in the Action column.  The conditions for each Action are noted in the table below.  I know I have to utilize peek and previous functions and possibly some temp tables but could use some assistance setting it up.  Any help is much appreciated it.

OrderCondition 1Condition 2Condition 3Condition 4Action
1EmployeeID NOT in previous Year_PeriodN/AEmployeeID NOT in next Year_PeriodN/AGain/Loss
2EmployeeID IS in previous Year_PeriodEmployeeID+Dept NOT in previous Year_PeriodEmployeeID NOT in next Year_PeriodN/ATransfer In/Loss
3EmployeeID IS in previous Year_PeriodEmployeeID+Dept IS in previous Year_PeriodEmployeeID NOT in next Year_PeriodN/ALoss
4EmployeeID NOT in previous Year_PeriodN/AEmployeeID IS in next Year_PeriodEmployeeID+Dept NOT in next Year_PeriodGain/Transfer Out
5EmployeeID NOT in previous Year_PeriodN/AEmployeeID IS in next Year_PeriodEmployeeID+Dept IS in next Year_PeriodGain
6EmployeeID IS in previous Year_PeriodEmployeeID+Dept NOT in previous Year_PeriodEmployeeID IS in next Year_PeriodEmployeeID+Dept NOT in next Year_PeriodTransfer In/Transfer Out
7EmployeeID IS in previous Year_PeriodEmployeeID+Dept NOT in previous Year_PeriodEmployeeID IS in next Year_PeriodEmployeeID+Dept IS in next Year_PeriodTransfer In
8EmployeeID IS in previous Year_PeriodEmployeeID+Dept IS in previous Year_PeriodEmployeeID IS in next Year_PeriodEmployeeID+Dept NOT in next Year_PeriodTransfer Out
Else    N/A

 

Here is what I have done so far...

Main:
LOAD
"Employee ID", //Key 1 for Gain/Loss
Department,
"Employee ID"&'-'&Department as TransferKey, //Create Key2 for Transfer In/Out
Year_Period
FROM [lib://Global_Finance_BIFileshare/Non-Application Related/Sample Data.xlsx]
(ooxml, embedded labels, table is Data);

//load distinct Employee IDs by Year_Period from resident to utilize
//ordering to enable peek/previous Employee ID from one Year_Period to the next

Key1:
load Distinct
"Employee ID",
Year_Period
Resident Main
order by "Employee ID",
Year_Period;

//load distinct TransferKey by Year_Period from resident to utilize
//ordering to enable peek/previous TransferKey from one Year_Period to the next

Key2:
Load Distinct
TransferKey,
Year_Period
Resident Main
order by TransferKey,
Year_Period;

 

0 Replies