Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Load multiple csv files into one file

I searched for and tried two suggestions below for loading multiple CSV files at once into a larger single file, but not having success. 


If someone can point out what I'm missing I would really appreciate it!

Attempt #1:

vPath = 'lib://AttachedFiles';

For each file in FileList('$(vPath)\example_data*.csv');

example_data_1234:

Load * FROM $(File)[lib://AttachedFiles/example_data*.csv]

(txt, codepage is 28591, embedded labels, delimiter is ',', msq);


Outcome:  The load runs, but Qlik Sense is creating a synthetic key using all the fields instead of making one table and appending with all the following files.  I expected it just be one table and not need a key of any kind.  Is there a way to avoid the synthetic key or does it matter?


Attempt #2

example_data_0398:


LOAD *

FROM [lib://AttachedFiles/example_DATA_APR1_15.csv];

Concatenate (example_data_0398);

LOAD *

FROM [lib://AttachedFiles/example_DATA_APR16_30.csv]

(txt, codepage is 28591, embedded labels, delimiter is ',', msq);


Outcome: I'm getting an error that says "Unknown statement: Concatenate (example_data_0398)"


1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

If you want to handle it with a load *, that is, you want to pick all the fields in each file even if they are different:

Data:

LOAD 0 as dummyfield AutoGenerate 0;


Concatenate (Data)

Load * FROM [lib://AttachedFiles/example_data*.csv]

(txt, codepage is 28591, embedded labels, delimiter is ',', msq);


DROP FIELD dummyfield;


Note there is no For Loop, just a wildcard in the filename.


-Rob

http://masterssummit.com

http://qlikviewcookbook.com

View solution in original post

7 Replies
ogster1974
Partner - Master II
Partner - Master II

Include the file name in your new table to avoid synthetic keys. Also rather than * I would identify the fields to load explicitly so you know the files are using the same file structure.

OmarBenSalem

delete the ; after the concatenate

Anonymous
Not applicable
Author

Hi, Andy!

I'm sorry, I'm not sure what you mean by "Include the file name in your new table to avoid synthetic keys".  Would you please provide an example?


Thank you!

Anonymous
Not applicable
Author

I knew it would be something simple like that and it did work!  Thank you!!

I'm interested to see how to make the other option work too so I'll have both options available.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

If you want to handle it with a load *, that is, you want to pick all the fields in each file even if they are different:

Data:

LOAD 0 as dummyfield AutoGenerate 0;


Concatenate (Data)

Load * FROM [lib://AttachedFiles/example_data*.csv]

(txt, codepage is 28591, embedded labels, delimiter is ',', msq);


DROP FIELD dummyfield;


Note there is no For Loop, just a wildcard in the filename.


-Rob

http://masterssummit.com

http://qlikviewcookbook.com

Anonymous
Not applicable
Author

Ahh, perfect.  Thank you for the help, Everyone!

gdisalvo2017
Contributor
Contributor

Thank you. This worked fine except it gave an error for the last statement -> DROP FIELD dummyfield;

Once removed it loaded perfect.