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

Vintage Dates

 Hi Experts

Need help on vintage dates  for example

I have two dates date of joining and termination date

If Any employee joins before 15th  of January month then it should be M0 Month ,feb as M1 ,March as M2,April As M3.................Dec as M11  and Next year Jan M12 ,Feb M13,March M14 ...etc.... and

 

If Any employee joins After 15th  of January month then it should be M0 Month ,feb as M0 ,March as M1,April As M2.................Dec as M10  and Next year Jan M11 ,Feb M12,March M13 ...etc....This should be created each month automatically .

Note : If the Termination date is not present then we can pick up today's date

Please find the attached sample data.

 

Thanks,

 

 

1 Solution

Accepted Solutions
pedrobergo
Employee
Employee

Hi @abubakarsiddiq7 

I generated a table using your rules, you can find it named FACTTABLE.

// Load Sample Data
SampleData:
LOAD
    S.no,
    Agent,
    "Date of Joining",
    Alt("Termination Date",Today())	AS "Termination Date"
FROM [lib://Sample/Sample Data.xlsx]
(ooxml, embedded labels, table is Sheet1);

// Creating a Calendar
CalendarTmp:
LOAD
    Date(Date) AS Date;
Load Date(MinDate + IterNo() -1 ) AS Date While (MinDate + IterNo() - 1) <= Num(MaxDate);
Load Min("Date of Joining")	AS MinDate,
	 Max("Termination Date") AS MaxDate
Resident SampleData;

// Create a CrossJoin between Calendar and SampleDate to generate date intervals
FactTableTmp:
NoConcatenate
Load Date
Resident CalendarTmp;
Left Join 
Load S.no,
	 "Date of Joining",
     "Termination Date"
Resident SampleData;
Drop Table CalendarTmp;

// Set flag 0-1 to each month considering 0 < Date > 15
FactTable2:
Load Distinct
	 MonthStart(Date) AS Date,
	 S.no,
     If(MonthName(Date)=MonthName("Date of Joining") OR 
     	(Day("Date of Joining")>15 AND MonthName(Date)=MonthName("Date of Joining")) OR
        	(Day("Date of Joining")>15 AND MonthName(Date)=MonthName(AddMonths("Date of Joining",1))),0,1)	AS Months
Resident FactTableTmp
WHERE Date>="Date of Joining"
AND Date<="Termination Date";
Drop Table FactTableTmp;

// Calculating M0, M1 and more
FactTable:
NoConcatenate
Load Date,
	 S.no,
     if(S.no=Peek(S.no),RangeSum(Peek(Months),Months),Months) AS Months,
     'M' & if(S.no=Peek(S.no),RangeSum(Peek(Months),Months),Months) AS QtMonths
Resident FactTable2
ORDER BY S.no, Date;
Drop Table FactTable2;
Drop Fields Months;

 [],

Pedro

View solution in original post

3 Replies
pedrobergo
Employee
Employee

Hi @abubakarsiddiq7 

I generated a table using your rules, you can find it named FACTTABLE.

// Load Sample Data
SampleData:
LOAD
    S.no,
    Agent,
    "Date of Joining",
    Alt("Termination Date",Today())	AS "Termination Date"
FROM [lib://Sample/Sample Data.xlsx]
(ooxml, embedded labels, table is Sheet1);

// Creating a Calendar
CalendarTmp:
LOAD
    Date(Date) AS Date;
Load Date(MinDate + IterNo() -1 ) AS Date While (MinDate + IterNo() - 1) <= Num(MaxDate);
Load Min("Date of Joining")	AS MinDate,
	 Max("Termination Date") AS MaxDate
Resident SampleData;

// Create a CrossJoin between Calendar and SampleDate to generate date intervals
FactTableTmp:
NoConcatenate
Load Date
Resident CalendarTmp;
Left Join 
Load S.no,
	 "Date of Joining",
     "Termination Date"
Resident SampleData;
Drop Table CalendarTmp;

// Set flag 0-1 to each month considering 0 < Date > 15
FactTable2:
Load Distinct
	 MonthStart(Date) AS Date,
	 S.no,
     If(MonthName(Date)=MonthName("Date of Joining") OR 
     	(Day("Date of Joining")>15 AND MonthName(Date)=MonthName("Date of Joining")) OR
        	(Day("Date of Joining")>15 AND MonthName(Date)=MonthName(AddMonths("Date of Joining",1))),0,1)	AS Months
Resident FactTableTmp
WHERE Date>="Date of Joining"
AND Date<="Termination Date";
Drop Table FactTableTmp;

// Calculating M0, M1 and more
FactTable:
NoConcatenate
Load Date,
	 S.no,
     if(S.no=Peek(S.no),RangeSum(Peek(Months),Months),Months) AS Months,
     'M' & if(S.no=Peek(S.no),RangeSum(Peek(Months),Months),Months) AS QtMonths
Resident FactTable2
ORDER BY S.no, Date;
Drop Table FactTable2;
Drop Fields Months;

 [],

Pedro

abubakarsiddiq7
Contributor III
Contributor III
Author

HI ,

Due to Left join it is creating so many records and unable to qlik is unable to handle the load can any one help me with other approach 

abubakarsiddiq7
Contributor III
Contributor III
Author

Due to Left join it is creating so many records and unable to qlik is unable to handle the load can you help me with other approach