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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Create the snapshot date for incremented data's

Hi All,

I have initially generate the snapshot date for my source file based upon the start and end date of the jobs.

Actual Source:(Source.qvd)

   

Job IdStart dateEnd date
J15/1/201712/31/9999
J25/2/201712/31/9999
J35/2/201712/31/9999

Snapshot date(today()-1 scenario) generated based upon the above source at initially like as below and store in (Test1.qvd)

  

Job IdSnap_Date
J15/1/2017
J15/2/2017
J15/3/2017
J15/4/2017
J15/5/2017
J15/6/2017
J15/7/2017
J25/1/2017
J25/2/2017
J25/3/2017
J25/4/2017
J25/5/2017
J25/6/2017
J25/7/2017
J35/1/2017
J35/2/2017
J35/3/2017
J35/4/2017
J35/5/2017
J35/6/2017
J35/7/2017

After that I was performing the I will perform the incremental load to get the update records from Source.qvd like as,

   

Job IdStart dateEnd date
J15/1/201712/31/9999
J25/2/201712/31/9999
J35/2/201712/31/9999
J45/7/201712/31/9999

From the above source I need to generate the snapshot date for J1,J2,J3,J4 like as below table.

  

Job IdSnap_Date
J15/8/2017
J25/8/2017
J35/8/2017
J45/7/2017
J45/8/2017

Can anyone give me suggestions to get it done

4 Replies
Anil_Babu_Samineni

You want to show Table like last one. But you mentioned Today()-1 and here, you may need Today()+1 for Max date.

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

Simply i put today () -1 scenario for reference. Daily basis, it need to get generate the snapshot date.

Anil_Babu_Samineni

What is your format?

May be this

Source: 

LOAD * INLINE  

Job IdStart dateEnd date
J15/1/201712/31/9999
J25/2/201712/31/9999
J35/2/201712/31/9999

]; 

NoConcatenate 

Final: 

LOAD 

  [Job Id], 

  Date([Start date],IterNo()-1) as [Start date]

  MakeDate(7,5,2017) as [To date] 

Resident Source 

While Date( [Start date]+IterNo()-1) <= [To date]; 

 

Drop Table Source;

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Digvijay_Singh

This should help you out -

Source:

Load * inline [

Job Id, Start date, End date

J1, 5/1/2017, 12/31/9999

J2, 5/2/2017, 12/31/9999

J3, 5/2/2017, 12/31/9999

J4, 5/7/2017, 12/31/9999 ];

if isnull(filetime('Test1.qvd')) then  //First time QVD is loaded with this script code;

  Test1:

  Load [Job Id], Date([Start date]  + iterno() -1) as Snap_Date

  resident Source

  While [Start date] + iterno() -1 <= today(1)-1;

  Store Test1 into Test1.qvd(qvd);

  drop table Source;

  EXIT SCRIPT;

end if

Test1:   //If QVD already exists, then load old records, we are also creating new temp Job ID field to compare later.

  LOAD [Job Id],

  [Job Id] as Temp_Job_Id,

      Snap_Date

  FROM

  Test1.qvd

  (qvd);

Temp2:    //We want to load new records for existing Job IDs from the last max date, don't need to repeat the logic from beginning.

Load [Job Id],

  max(Snap_Date) as Max_Date

Resident Test1

Group By [Job Id];

Concatenate(Test1) //This will load existing job Ids with new snap date from last loaded date to today date.

Load  [Job Id],

   Date(Max_Date  + IterNo() ) as Snap_Date

Resident Temp2

While Max_Date + IterNo() <= today(1)-1;

NoConcatenate

Temp1:  //This will get newly added job Ids in the source file. This logic can be even added before above mentioned logic of identifying max dates.

Load *

Resident Source

Where not exists(Temp_Job_Id,[Job Id]);

Concatenate(Test1) //This will create snap dates for newly added job ids.

Load [Job Id],

  Date([Start date]  + IterNo() -1) as Snap_Date

Resident Temp1

While [Start date] + IterNo() -1 <= today(1);

;

Store Test1 into Test1.qvd(qvd);

drop table Source,Temp1,Temp2;

drop field Temp_Job_Id;