<?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: For Each loop with condition on filename in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/For-Each-loop-with-condition-on-filename/m-p/817799#M288327</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I realized a silly mistake in the variable used in the From-Load. Now I got a working version: FYI see below&lt;/P&gt;&lt;P&gt;Nevertheless I would be interested if there are other concepts to solve this.&lt;/P&gt;&lt;P&gt;E.g. When simply loading by LOAD *&amp;nbsp;&amp;nbsp; -&amp;gt; Qlik creates a new table for each time the field structure is different and I would need again a loop to concatenate them...so not sure if this would be more efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just for your interest the working script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SET vSourcePath = 'G:\Documents\Desktop\ForEach_FileName\';&lt;/P&gt;&lt;P&gt;SET vSourceFile = 'TestFile_*.xlsx';&lt;/P&gt;&lt;P&gt;SET vSource = '$(vSourcePath)$(vSourceFile)';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FOR Each vPathAndFile in FileList(vSource);&lt;/P&gt;&lt;P&gt;LET vSingleFile = left(SubField(vPathAndFile,'TestFile_',2),1) ;&lt;/P&gt;&lt;P&gt;if $(vSingleFile) &amp;lt; 3 then&amp;nbsp; &lt;/P&gt;&lt;P&gt;Old:&lt;/P&gt;&lt;P&gt;LOAD &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'old' as Status,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Testfield1&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;$(vPathAndFile)&lt;/P&gt;&lt;P&gt;(ooxml, embedded labels, table is Sheet1); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ELSEIF $(vSingleFile) = 3 then&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;New:&lt;/P&gt;&lt;P&gt;LOAD &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'new' as Status,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID as ID, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Testfield1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Testfield2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;$(vPathAndFile)&lt;/P&gt;&lt;P&gt;(ooxml, embedded labels, table is Sheet1); &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;NEXT vPathAndFile&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Mar 2015 02:11:33 GMT</pubDate>
    <dc:creator>danieloberbilli</dc:creator>
    <dc:date>2015-03-03T02:11:33Z</dc:date>
    <item>
      <title>For Each loop with condition on filename</title>
      <link>https://community.qlik.com/t5/QlikView/For-Each-loop-with-condition-on-filename/m-p/817797#M288325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have two sets of Excel source files: 'old' and 'new'. I need to load both sets each day. The 'new' set contain additional fields that aren't available in the 'old' set. The filenames contain a datecode that I can use to identify whether a file belongs to old or new and therefore which fields are available.&lt;/P&gt;&lt;P&gt;My idea was to use a For Each loop, save the date-information in a variable (vSingleFile -seems to work) and then use If Then Else to load either the old or the new data table (&amp;lt;3 load old,&amp;nbsp; =3 load new). But my script fails and it seems that my If Then else does not work for whatever reason.&lt;/P&gt;&lt;P&gt;This simplified example has 3 Excel tables: TestFile_1 and TestFile_2 are the old ones&amp;nbsp; and TestFile_3 is the new one. Testfield1 represents the old fields, Testfield2 the new additional fields. Please be aware that I am dealing with hundreds of files.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;SET vSourcePath = 'G:\Documents\Desktop\ForEach_FileName\';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;SET vSourceFile = 'TestFile_*.xlsx';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;SET vSource = '$(vSourcePath)$(vSourceFile)';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;FOR Each vPathAndFile in FileList(vSource);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: courier new,courier;"&gt;&lt;STRONG&gt;LET vSingleFile = left(SubField(vPathAndFile,'TestFile_',2),1) ;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;if $(vSingleFile) &amp;lt; 3 then&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;LOAD &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'old' as Status,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Testfield1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;FROM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;$(vSourceFile)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;(ooxml, embedded labels, table is Sheet1); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;ELSE &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;LOAD &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'new' as Status,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Testfield1,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Testfield2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;FROM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;$(vSourceFile)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;(ooxml, embedded labels, table is Sheet1); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;ENDIF&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: courier new,courier;"&gt;NEXT vPathAndFile&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot in Advance.&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 00:11:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/For-Each-loop-with-condition-on-filename/m-p/817797#M288325</guid>
      <dc:creator>danieloberbilli</dc:creator>
      <dc:date>2015-03-03T00:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: For Each loop with condition on filename</title>
      <link>https://community.qlik.com/t5/QlikView/For-Each-loop-with-condition-on-filename/m-p/817798#M288326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As alternative I tried to have one table script only with if()-conditions within the table for the new fields like:&lt;/P&gt;&lt;P&gt;if($(vSingleField)=3, Testfield_2, null()) as Testfield_2,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but didnt work neither&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 00:17:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/For-Each-loop-with-condition-on-filename/m-p/817798#M288326</guid>
      <dc:creator>danieloberbilli</dc:creator>
      <dc:date>2015-03-03T00:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: For Each loop with condition on filename</title>
      <link>https://community.qlik.com/t5/QlikView/For-Each-loop-with-condition-on-filename/m-p/817799#M288327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I realized a silly mistake in the variable used in the From-Load. Now I got a working version: FYI see below&lt;/P&gt;&lt;P&gt;Nevertheless I would be interested if there are other concepts to solve this.&lt;/P&gt;&lt;P&gt;E.g. When simply loading by LOAD *&amp;nbsp;&amp;nbsp; -&amp;gt; Qlik creates a new table for each time the field structure is different and I would need again a loop to concatenate them...so not sure if this would be more efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just for your interest the working script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SET vSourcePath = 'G:\Documents\Desktop\ForEach_FileName\';&lt;/P&gt;&lt;P&gt;SET vSourceFile = 'TestFile_*.xlsx';&lt;/P&gt;&lt;P&gt;SET vSource = '$(vSourcePath)$(vSourceFile)';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FOR Each vPathAndFile in FileList(vSource);&lt;/P&gt;&lt;P&gt;LET vSingleFile = left(SubField(vPathAndFile,'TestFile_',2),1) ;&lt;/P&gt;&lt;P&gt;if $(vSingleFile) &amp;lt; 3 then&amp;nbsp; &lt;/P&gt;&lt;P&gt;Old:&lt;/P&gt;&lt;P&gt;LOAD &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'old' as Status,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Testfield1&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;$(vPathAndFile)&lt;/P&gt;&lt;P&gt;(ooxml, embedded labels, table is Sheet1); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ELSEIF $(vSingleFile) = 3 then&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;New:&lt;/P&gt;&lt;P&gt;LOAD &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'new' as Status,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID as ID, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Testfield1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Testfield2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;$(vPathAndFile)&lt;/P&gt;&lt;P&gt;(ooxml, embedded labels, table is Sheet1); &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;NEXT vPathAndFile&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Mar 2015 02:11:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/For-Each-loop-with-condition-on-filename/m-p/817799#M288327</guid>
      <dc:creator>danieloberbilli</dc:creator>
      <dc:date>2015-03-03T02:11:33Z</dc:date>
    </item>
  </channel>
</rss>

