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

I have issue Load multiple csv files with with different header line

Hi 

I have 3 csv files in a location   sales1.csv,  sales2.csv, sales3.csv  I am using For each loop next to load all files. but it is failing to load the last file because the header line is different from the first 2 "  (txt, codepage is 28591, embedded labels, delimiter is  ',', msq, header is 2 line) "  vs   (txt, codepage is 28591, embedded labels, delimiter is  ',', msq) for the first 2.

how can I take care of the issue  since in cannot modified the last file Sales3.csv

For Each vFiles in Filelist ('$(Filepath)/*.csv')

     Sales:

      Load 

     *

    From $(vFiles)

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

Next vFiles ;

 

Labels (4)
2 Solutions

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

For Each vFiles in Filelist ('$(Filepath)/*.csv')

Let vHeader = if('$(vFiles)' like '*sales3.csv', 2, 0);

     Sales:

      Load 

     *

    From $(vFiles)

    (txt, codepage is 28591, embedded labels, delimiter is  ',', msq, header is $(vHeader) line);

Next vFiles ;

-Rob

View solution in original post

Taoufiq_Zarra

For Each vFile in FileList('$(FilePath)/*.csv')

// Check if the file name is 'sales3.csv'
If vFile = 'sales3.csv' Then
Load
*
From [$(vFile)]
(txt, codepage is 28591, embedded labels, delimiter is ',', msq, header is 2 lines);
Else
Load
*
From [$(vFile)]
(txt, codepage is 28591, embedded labels, delimiter is ',', msq);
End If

Next vFile

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

2 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

For Each vFiles in Filelist ('$(Filepath)/*.csv')

Let vHeader = if('$(vFiles)' like '*sales3.csv', 2, 0);

     Sales:

      Load 

     *

    From $(vFiles)

    (txt, codepage is 28591, embedded labels, delimiter is  ',', msq, header is $(vHeader) line);

Next vFiles ;

-Rob

Taoufiq_Zarra

For Each vFile in FileList('$(FilePath)/*.csv')

// Check if the file name is 'sales3.csv'
If vFile = 'sales3.csv' Then
Load
*
From [$(vFile)]
(txt, codepage is 28591, embedded labels, delimiter is ',', msq, header is 2 lines);
Else
Load
*
From [$(vFile)]
(txt, codepage is 28591, embedded labels, delimiter is ',', msq);
End If

Next vFile

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉