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

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
a-5
Contributor III
Contributor III

Loading data from csv files including monthly data

Hi!

I'm trying to load data from monthly csv files (with naming DATA_202201, DATA_202202 etc.) and I'm trying to load data from last year's January onwards. I've written the below code, but it doesn't work - I manage to generate the AR_Dates table correctly, but reading the csv files doesn't work. I get an error message that the csv file can't be opened. 

LET vStartDateAR=num(YearStart(AddYears(MonthStart(Today()),-1)));
LET vEndDateAR=num(Date(Today(),'YYYYMM'));
 
[AR_Dates]:
Load
distinct 
date(MonthStart(Date($(vStartDateAR) + IterNo()-1)),'YYYYMM') as DateAR
autogenerate 1
WHILE $(vStartDateAR) + IterNo() <= $(vEndDateAR);
 
 
for i=1 to NoOfRows('AR_Dates')
let vFileDateAR=Peek('DateAR', i, 'AR_Dates');
    let vSortAR=i;
    
LOAD *
FROM [lib://DATA_$(vFileDateAR).csv]
(txt, utf8, embedded labels, delimiter is ',', msq);
 
next i;
 
Can you please advise?
Labels (1)
1 Solution

Accepted Solutions
Aasir
Creator III
Creator III

Everything looks Ok just review your file path in the FROM clause.
Create a variable like below to concatenate the file path and the file name properly.

LET vFilePath = 'lib://DATA_' & vFileDateAR & '.csv';

LOAD * FROM [$(vFilePath)] (txt, utf8, embedded labels, delimiter is ',', msq);

NEXT i;

3 more things to check in these cases 1. file path, 2. file permissions, 3. file existence

View solution in original post

1 Reply
Aasir
Creator III
Creator III

Everything looks Ok just review your file path in the FROM clause.
Create a variable like below to concatenate the file path and the file name properly.

LET vFilePath = 'lib://DATA_' & vFileDateAR & '.csv';

LOAD * FROM [$(vFilePath)] (txt, utf8, embedded labels, delimiter is ',', msq);

NEXT i;

3 more things to check in these cases 1. file path, 2. file permissions, 3. file existence