Qlik Community

New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

cancel
Showing results for 
Search instead for 
Did you mean: 
dmg17188
Contributor II
Contributor II

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

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
Master II
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
Partner
Partner

delete the ; after the concatenate

dmg17188
Contributor II
Contributor II
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!

dmg17188
Contributor II
Contributor II
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

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

dmg17188
Contributor II
Contributor II
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.