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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
azucna122
Partner - Creator
Partner - Creator

load the last 5 months in qvd

Hi, I am new to qlik,

I have some qvd partitioned in months, with the format:

Sales_202310.qvd
Sales_202309.qvd
Sales_202308.qvd
Sales_202307.qvd
Sales_202306.qvd
... Sales_202301.qvd

i want to load in my qlik, only the last 5 months (oct - jun).

this is code i have, that loads only the current month, how can i load in addition to the current month 4 more months? :

Let lastmonth = Date(today(),'YYYYYYMM');
TmpData:
LOAD
LAST_DATE_LOAD,
SALES
FROM QVDS\SALES_$(lastmonth).QVD(qvd)
;

1 Solution

Accepted Solutions
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Apologies my bad, the code goes to 5 months in future where as we have to go in history,

Please change below code.

For i=0 to 4
Let lastmonth = Date(Addmonths(today(),-$(i)),'YYYYMM');
TmpData:
LOAD
LAST_DATE_LOAD,
SALES
FROM QVDS\SALES_$(lastmonth).QVD(qvd)
;
Next

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!

View solution in original post

8 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

You can run through a loop like below

For i=0 to 4 //Because it includes 0 as well

Let lastmonth = Date(Addmonths(today(),$(i)),'YYYYMM');

TmpData:
LOAD
LAST_DATE_LOAD,
SALES
FROM QVDS\SALES_$(lastmonth).QVD(qvd)
;

Next

 

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
azucna122
Partner - Creator
Partner - Creator
Author

Hello Kaushik,
thanks for your quick reply!
I'm getting an error, try to search for the november qvd (202311) ... 

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

In such case change your for statement from

For i=0 to 4 

To

For i=1 to 5

 

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
azucna122
Partner - Creator
Partner - Creator
Author

hi Kaushik

I have changed the loop to For i=1 to 5 and the process is still trying to find the qvd Sales_202311.qvd ...

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Please share your script.

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
azucna122
Partner - Creator
Partner - Creator
Author

code: 

For i=1 to 5
Let lastmonth = Date(Addmonths(today(),$(i)),'YYYYMM');
TmpData:
LOAD
LAST_DATE_LOAD,
SALES
FROM QVDS\SALES_$(lastmonth).QVD(qvd)
;
Next

script error: 

Unable to open the file 'QVDS\SALES_202311.QVD' The system cannot find the specified file.

TmpData:
LOAD
LAST_LOAD_DATE,
SALES
FROM QVDS\SALES_202311.QVD(qvd)

 

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Apologies my bad, the code goes to 5 months in future where as we have to go in history,

Please change below code.

For i=0 to 4
Let lastmonth = Date(Addmonths(today(),-$(i)),'YYYYMM');
TmpData:
LOAD
LAST_DATE_LOAD,
SALES
FROM QVDS\SALES_$(lastmonth).QVD(qvd)
;
Next

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
azucna122
Partner - Creator
Partner - Creator
Author

Thank you so much Kaushik!
That was it!