Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Przemyslaw_Rybacki
Contributor II
Contributor II

Dynamic loading file based on file name

Hello Everyone,

I have in my folder below standing files, which are stored with year_month time stamp : 

Orders_2020_01.qvd

.....

Orders_2020_09.qvd

I need to load dynamically last 30 days.

I was trying this script, but have this error:

Unexpected token: '_01', expected one of: 'OPERATOR_PLUS', 'OPERATOR_MINUS', 'OPERATOR_MULTIPLICATION', 'OPERATOR_DIVISION', 'OPERATOR_STRING_CONCAT', 'like', 'and', ...

IF 2010>>>>>>_01<<<<<< >= 2020_08 THEN

 

SCRIPT:

LET vDateLimitMax = DATE(today(),'YYYY_MM') ;

LET vDateLimitMin = DATE(today()-30,'YYYY_MM');

SET FileDate = '';

trace loop start;

trace;

for each File in filelist ('lib://MY_PATH/*.qvd')

SET sFile = '$(File)';

LET FileDate = left(right(sFile,11),7);

trace *** processing $(File) dated $(FileDate);

IF $(FileDate) >= $(vDateLimitMin) THEN

Directory;

TABLE:

LOAD * FROM [$(sFile)](txt, codepage is 28591, no labels, delimiter is '\t', msq);

trace file loaded;

trace;

ELSE

trace file ignored;

trace;

ENDIF

next File

trace loop end;

This solution I found here 

https://community.qlik.com/t5/New-to-Qlik-Sense/How-to-load-last-12-months-files-dynamically/td-p/91...

Thanks for help!

4 Replies
Przemyslaw_Rybacki
Contributor II
Contributor II
Author

Hey Community,

any idea?

prerakdt
Contributor II
Contributor II

Looks like the error is because your file name is not exactly matching with the thread you are taking reference. See the screenshot of that thread below. 

prerakdt_0-1600246301804.png

 

Przemyslaw_Rybacki
Contributor II
Contributor II
Author

Thank you replay!

This link is just a solution which i found and I was trying to use in my case.

https://community.qlik.com/t5/New-to-Qlik-Sense/How-to-load-last-12-months-files-dynamically/td-p/91...

MY problem occurs here:

Unexpected token: '_01', expected one of: 'OPERATOR_PLUS', 'OPERATOR_MINUS', 'OPERATOR_MULTIPLICATION', 'OPERATOR_DIVISION', 'OPERATOR_STRING_CONCAT', 'like', 'and', ...

IF 2010>>>>>>_01<<<<<< >= 2020_08 THEN

 

 

 

 

 

Ondrism
Contributor III
Contributor III

You need to convert the time format from a string to a value ($(FileDate)) to compare in an if condition. Now it takes your value in the condition as a string and it can't be compared.