Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
josemaria_cabre
Contributor III
Contributor III

Load sales month script

Hi everyone,

I wrote this code to load different sales files by month:

FOR i = 1 to 12

    // Generate file name based on month
    LET vMonth = Pick(i,
        'january', 'february', 'march', 'april', 'may', 'june',
        'july', 'august', 'september', 'october', 'november', 'december'
        );
    
    trace $(i);
    trace $(vMonth);
    // File path 
    LET vFile = 'lib://MyData/sales_' & vMonth & '.csv';
    trace $(vFile);
    // Load data from file
    Sales:
    LOAD
        Date,
        Product,
        Amount,
        Price
         FROM [$(vFile)]
(txt, utf8, embedded labels, delimiter is ';', msq);

NEXT i

If I only have 2 files (e.g "sales_january.csv" and "sales_february.csv") in MyData directory, I get a "Cannot open file 'lib://MyData/sales_march.csv' error.

How can I load only existing files without getting this error?

Thanks in advance for your help,
Jose

Labels (1)
1 Reply
vinieme12
Champion III
Champion III

Check if File exists 

 

IF FileSize($(vFile)) > 0 Then 

Sales:

Load *

From [$(vFile)]

End IF

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.