Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Import multiple .csv files with same headers

Hi there

I have multiple (monthly) .csv files which need to be imported.  Each is named EmpFinFile 201507, EmpFinFile201508, EmpFinFile201509, etc. How do I create a script that imports each file using 1 load which loops or iterates for each month?  Instead of having multiple load statements for each file resulting in a very long script!

7 Replies
Gysbert_Wassenaar

Use a wildcard load:

LOAD * FROM EmpFinFile*.csv (txt, codepage is 1252, embedded labels, delimiter is ',', msq);


If you do use a wildcard load then all the csv files must have the exact same fields. Otherwise you need a loop like the example in this discussion: loop through to load all files from a folder and its subfolders?


talk is cheap, supply exceeds demand
hareeshkumar_gv
Contributor III
Contributor III

use the following load statement

load * from path/EmpFinFile*.csv

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

Please make sure all the csv files in the same folder

sacosta5
Contributor III
Contributor III

santiago_respane
Specialist
Specialist

Hi, you have two options:

-Wildcard load

Load * from EmpFinFile*.csv (txt, codepage is 1252, embedded labels, delimiter is ',', msq);

-Loop through files and load data

For Each File in filelist ($(PathToDirectory)EmpFinFile*.csv')')
YourTable:
LOAD * FROM '$(File)' (txt, codepage is 1252, embedded labels, delimiter is ',', msq);

NEXT File;

I prefer looping through files because, when using wildcard load, if directory is empty and there are no files to load Qlikview will throw an error and your script will fail.

Hope this helps,

MarcoWedel

Hi,

you can include a field in your load statement to distinguish between the different file months like:

LOAD *,

          MonthName(Date#(Right(FileBaseName(),6),'YYYYMM')) as FileMonth

From *.CSV ...

hope this helps

regards

Marco

Not applicable
Author

I got identical files (fields) from different systems that I need to merge. One is FCode12.csv, another ist FCode3.csv and so on.

The only difference is the data contained therein, file FCode12.csv contains all 1xx and 2xx errors, FCode3.csv all 3xx errors etc.

I used the proposed technique to have them loaded by use of wildcard (see below for my code), however I get the import as different tables and fields (Error.Fcode, Error1.Fcode ....)

the only difference to your proposed solution with wildcard is, that I have to qualify the importsw, because we got to load other tables that have same field names as other tables. I learned to prevent mixup, you have to use the 'Qualify' statement ...? 

Any sugestion how to load those duplicated files?

Note: those files below are the most simple tables. For my application I have to load 12 different CSV files, all with several duplicates to it and partially up to 60 fileds in it ...  so loading them 1:1 is not an option, I need to have a bulk import for each cluster ....

Greatful for any tips or hints on how to achive that data load. 🙂


//***************** Table(Tbl) Error from FCode*.csv in /Test subfolder **********************

QUALIFY *;

UNQUALIFY '%*';

Error:

LOAD

    Meldung as %MeldungFCode, //Unique Key for this Tbl, link to Tbl Fact_Service

    Position,

    Schadenscode,

    "Kurztext zum Code"

FROM [lib://Belimed/Test/FCode*.csv]

(txt, utf8, embedded labels, delimiter is '\t', msq);

UNQUALIFY *;

MarcoWedel

please open a new thread for your question

thanks

regards

Marco