<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Import files one at a time, check for fields, and overwrite existing files in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941522#M951111</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A possible optimization might be to load only the first record from Test1:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test1:&lt;/P&gt;&lt;P&gt;First 1 Load ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then the second load Test2 to load again from the qvd. But you will need larger datasets to see here noticable differences.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But a bigger improvement could be to skip these task completely. Then it's often not necessary to hold a month/year field within a table if you have a date which could be later connected with a master-calendar which provides all needed period-fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 07 Dec 2015 17:02:39 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2015-12-07T17:02:39Z</dc:date>
    <item>
      <title>Import files one at a time, check for fields, and overwrite existing files</title>
      <link>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941518#M951107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hi, I need some help automating ETL code to run on multiple files in a folder, one at a time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have over a year's worth of data broken down into monthly files.&amp;nbsp; We've been building these files over the year and the script has occasionally changed, causing some of these files to randomly have 2 extra fields.&amp;nbsp; I need all the files to have these extra fields.&amp;nbsp; The files either contain both or neither, and the fields are just a calculation from existing fields so no extra data is needed.&amp;nbsp;&amp;nbsp; I need the monthly dated file structure to remain the same – this script is just to add the fields if necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is across ~90 files with different naming conventions and fields, but the two I am trying to add are consistent across all files..&amp;nbsp; All are in one folder.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Filename syntax eg.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; AgentSourceData_20141101.qvd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; AgentSourceData_20141201.qvd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; TeamSourceData_20151101.qvd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; TeamSourceData_20151201.qvd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; CentreSourceData_20151201.qvd&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to be able to run a fairly automated script that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Import a file,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Check if it has these extra columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if true, discard data and import next file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If false, add the columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Export to the same filename, overwriting the existing file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Discard data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Import the next file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I’ve written the code below which works, but obviously only on one specific file at a time.&amp;nbsp; I need to know how to make it loop through all the files in the folder without me having to specify each one individually. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test1:&lt;/P&gt;&lt;P&gt;Load *&lt;/P&gt;&lt;P&gt;FROM&amp;nbsp; [AgentSourceData_20151101.qvd](qvd);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF FieldNumber('DateYear','Test1')=0 then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test2:&lt;/P&gt;&lt;P&gt;&amp;nbsp; Load *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Year(Date) as "DateYear"&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Month(Date) as "DateMonth"&lt;/P&gt;&lt;P&gt;&amp;nbsp; Resident Test1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Store Test2 into [AgentSourceData_20151101.qvd];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drop Table Test2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drop table Test1;&lt;/P&gt;&lt;P&gt;Else&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drop table Test1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Endif;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test1:&lt;/P&gt;&lt;P&gt;Load *&lt;/P&gt;&lt;P&gt;FROM&amp;nbsp; [AgentSourceData_20151201.qvd](qvd);&lt;/P&gt;&lt;P&gt;etc...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that makes sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Dave&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Dec 2015 23:30:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941518#M951107</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-12-02T23:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Import files one at a time, check for fields, and overwrite existing files</title>
      <link>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941519#M951108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You want to load all the QVDs in folder and want to create the Year &amp;amp; Month from file name?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Dec 2015 12:06:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941519#M951108</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2015-12-03T12:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Import files one at a time, check for fields, and overwrite existing files</title>
      <link>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941520#M951109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For such things you could use filelist to loop through your folders and then make your checks on topics like filetime/filesize or the contained fields whereby it's enough to read only one record with the first-statement and by qvd-files you could also use the file-functions like qvdfieldname() and qvdnooffields(). If you searched on filelist you will find many examples like this one: &lt;A href="https://community.qlik.com/message/881986"&gt;Re: Pick the latest excel file from folders&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Dec 2015 14:59:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941520#M951109</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2015-12-03T14:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Import files one at a time, check for fields, and overwrite existing files</title>
      <link>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941521#M951110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Marcus.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This was my finalised working script.&amp;nbsp; I had to add some additional logic to look using the LEN function to look into the columns if they existed and recreate if there was no data in there as we had some files with the column headings but no data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is working, but any suggestions for optimisation / improvement are welcome. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each vFileName in Filelist ('$(SDL_Directory)*')&lt;/P&gt;&lt;P&gt;Test1:&lt;/P&gt;&lt;P&gt;Load *&lt;/P&gt;&lt;P&gt;from [$(vFileName)] (qvd);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF FieldNumber('DateYear','Test1')=0 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; Test2:&lt;/P&gt;&lt;P&gt;&amp;nbsp; Load *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Year(Date) as "DateYear"&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Month(Date) as "DateMonth"&lt;/P&gt;&lt;P&gt;&amp;nbsp; Resident Test1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Store Test2 into [$(vFileName)];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drop Table Test2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drop table Test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Else&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF len(peek('DateYear',0,'Test1'))&amp;nbsp; =0 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop fields DateYear, DateMonth;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Test2:&lt;/P&gt;&lt;P&gt;&amp;nbsp; Load *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Year(Date) as "DateYear"&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Month(Date) as "DateMonth"&lt;/P&gt;&lt;P&gt;&amp;nbsp; Resident Test1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Store Test2 into [$(vFileName)];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drop Table Test2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drop table Test1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ELSE&lt;/P&gt;&lt;P&gt;&amp;nbsp; Drop table Test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ENDIF;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Endif;&lt;/P&gt;&lt;P&gt;ENDIF;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Next vFileName;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Dave&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Dec 2015 00:12:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941521#M951110</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-12-07T00:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: Import files one at a time, check for fields, and overwrite existing files</title>
      <link>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941522#M951111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A possible optimization might be to load only the first record from Test1:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test1:&lt;/P&gt;&lt;P&gt;First 1 Load ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then the second load Test2 to load again from the qvd. But you will need larger datasets to see here noticable differences.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But a bigger improvement could be to skip these task completely. Then it's often not necessary to hold a month/year field within a table if you have a date which could be later connected with a master-calendar which provides all needed period-fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Dec 2015 17:02:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941522#M951111</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2015-12-07T17:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: Import files one at a time, check for fields, and overwrite existing files</title>
      <link>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941523#M951112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great advice on the 1st row.&amp;nbsp; Some of these QVDs are huge, that will save significant time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Without going into the boring detail, the month/year columns are needed for an daily automated extraction script.&amp;nbsp;&amp;nbsp; When they go through an ETL script once a week to bring into our dashboard these columns are indeed dropped and linked to a master calendar. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers again. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Dec 2015 06:50:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Import-files-one-at-a-time-check-for-fields-and-overwrite/m-p/941523#M951112</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-12-08T06:50:32Z</dc:date>
    </item>
  </channel>
</rss>

