<?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: Load specific Excel sheet with variable name in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1806459#M65594</link>
    <description>&lt;P&gt;Alright, thank you everyone for helping! I spent some time trying to use an ODBC connection to load the Excel file, but I encountered technical problems in my organization so I could not really test it.&lt;/P&gt;&lt;P&gt;Nevertheless, I kept on modifying the code and discovered that the problem was "FileBaseName()" which was not returning anything and therefore the variable vSheetName remained empty.&lt;/P&gt;&lt;P&gt;The solution was to replace FileBaseName() with File, the variable I was already using for the For loop. Final working code below.&lt;/P&gt;&lt;P&gt;-------------------------&lt;/P&gt;&lt;P&gt;For each File in FileList('[lib://xxx/xxx Statistic - *.xlsx]')&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;let vSheetName = left(right(subfield('$(File)', ' - ', -1), 8), 3) &amp;amp; ' ' &amp;amp; left(subfield('$(File)', ' - ', -1), 4);&amp;nbsp;&lt;BR /&gt;TRACE $(vSheetName);&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Table:&lt;BR /&gt;LOAD *&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;From $(File)&lt;BR /&gt;(ooxml, embedded labels, table is '$(vSheetName)';&lt;/P&gt;&lt;P&gt;NEXT File;&lt;/P&gt;</description>
    <pubDate>Mon, 10 May 2021 07:14:13 GMT</pubDate>
    <dc:creator>Nwinx1984</dc:creator>
    <dc:date>2021-05-10T07:14:13Z</dc:date>
    <item>
      <title>Load specific Excel sheet with variable name</title>
      <link>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805269#M65439</link>
      <description>&lt;P&gt;Hello, I am new to Qlik app creation and I need to load many Excel files from a folder&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Filename format:&amp;nbsp;"TEXT - YYYY MMM.xlsx" (e.g. "Text - 2021 Jan", "Text - 2021 Feb", etc...)&lt;/LI&gt;&lt;LI&gt;Sheet name format:&amp;nbsp;"MMM YYYY" (e.g. "Jan 2021", "Feb 2021", etc...). This is always the second sheet in the file.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It should be easy to extract from this the year and the month to tell the load editor which Excel table to load, but somehow, the variable containing the sheet name is not being evaluated properly.&lt;/P&gt;&lt;P&gt;My code (based on a thousand forum answers) is the following:&lt;/P&gt;&lt;P&gt;-----------------------------------------&lt;/P&gt;&lt;P&gt;//Before this code I set the structure of the "Tickets" table, which contain the Distributor, Date, Month and Year fields&lt;/P&gt;&lt;P&gt;For each File in FileList('[lib://xxx/xxx/Statistic - *.xlsx]')&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;TempSheetName:&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;LOAD&lt;BR /&gt;right(subfield(filebasename( ), ' - ', -1), 3) &amp;amp; ' ' &amp;amp; left(subfield(filebasename( ), ' - ', -1), 4) as SheetName;&lt;BR /&gt;set vSheetName = SheetName;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Table1:&lt;BR /&gt;Concatenate (Tickets)&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;LOAD&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;//Material is the header of one of the columns in sheet 2&lt;BR /&gt;If(Material='4600081' OR Material='4600083', 'SJ',&lt;/P&gt;&lt;P class="lia-indent-padding-left-90px"&gt;If(Material='4608125', 'N/A - Sales Message (SM)/pc', Material&lt;BR /&gt;)&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;) As [Distributor],&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;//...&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&lt;BR /&gt;"Date",&lt;BR /&gt;Month("Date") as "Month",&lt;BR /&gt;Year("Date") as "Year"&lt;BR /&gt;&lt;BR /&gt;From $(File)&lt;BR /&gt;(ooxml, embedded labels, table is [$(vSheetName)]);&lt;BR /&gt;DROP Table TempSheetName;&lt;/P&gt;&lt;P&gt;NEXT File;&lt;/P&gt;&lt;P&gt;-------------------------------&lt;/P&gt;&lt;P&gt;Explanation: I create a temp table (I'm not expert at all and I haven't figured out yet the importance of a resident load in this case) where I calculate and store the Excel sheet name based on the file name (I've tested this part separately and it works. Then I set a variable vSheetName that contains that value and I use that variable to specify the name of the Excel sheet to load. (I tried both SET and LET with no success)&lt;/P&gt;&lt;P&gt;When I try to load data, I get the error:&lt;/P&gt;&lt;P&gt;"The following error occurred: Field 'Material' not found" and at the bottom of the error report, where the full problematic code is displayed, it seems that the variable&amp;nbsp;$(File) is correctly used but $(vSheetName) is not:&lt;/P&gt;&lt;P&gt;"&lt;SPAN&gt;(ooxml, embedded labels, table is ***)".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please note I have tried every possible format to use the variable: $(vSheetName), [$vSheetName], [$(vSheetName)],&amp;nbsp;@$vSheetName,&amp;nbsp;@2 (meaning "Sheet 2", apparently deprecated now) and many more, but nothing is working (it seems like everybody on this forum uses a different format!!!)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It seems so strange to me that it is so hard to load the second sheet in an XLSX file! Am I missing something? Any help would be appreciated, thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 08:00:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805269#M65439</guid>
      <dc:creator>Nwinx1984</dc:creator>
      <dc:date>2021-05-05T08:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Load specific Excel sheet with variable name</title>
      <link>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805279#M65442</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/140849"&gt;@Nwinx1984&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try like below while storing the sheet name in variable&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Let vSheetName = Peek('SheetName');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Check the value in the variable.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 08:10:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805279#M65442</guid>
      <dc:creator>MayilVahanan</dc:creator>
      <dc:date>2021-05-05T08:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Load specific Excel sheet with variable name</title>
      <link>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805287#M65445</link>
      <description>&lt;P&gt;Nothing changed unfortunately.&lt;/P&gt;&lt;P&gt;I've also added a line to load the variable in another existing column in the table:&lt;/P&gt;&lt;P&gt;[...]&lt;/P&gt;&lt;P&gt;'$(vSheetName)' as "Code"&lt;/P&gt;&lt;P&gt;[...]&lt;/P&gt;&lt;P&gt;but it is evaluated to ' ' (blank).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 08:22:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805287#M65445</guid>
      <dc:creator>Nwinx1984</dc:creator>
      <dc:date>2021-05-05T08:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Load specific Excel sheet with variable name</title>
      <link>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805293#M65446</link>
      <description>&lt;P&gt;Can you paste ur full script?&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 08:26:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805293#M65446</guid>
      <dc:creator>MayilVahanan</dc:creator>
      <dc:date>2021-05-05T08:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Load specific Excel sheet with variable name</title>
      <link>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805298#M65447</link>
      <description>&lt;P&gt;Should the code not be like this? Looks like you omitted the source (see Bold text)&lt;/P&gt;&lt;P&gt;LOAD&lt;BR /&gt;right(subfield(filebasename(), ' - ', -1), 3) &amp;amp; ' ' &amp;amp; left(subfield(filebasename(), ' - ', -1), 4) as SheetName&lt;BR /&gt;&lt;STRONG&gt;FROM $(File); // Need to add this&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;LET vSheetName = peek('SheetName');&lt;/P&gt;&lt;P&gt;TRACE $(vSheetName); // Show result in log&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 08:42:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805298#M65447</guid>
      <dc:creator>eddie_wagt</dc:creator>
      <dc:date>2021-05-05T08:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Load specific Excel sheet with variable name</title>
      <link>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805304#M65450</link>
      <description>&lt;P&gt;I don't know if the FROM statement is needed or not (in this case I am not importing anything from that file, I am just storing part of the filename in a new column).&lt;/P&gt;&lt;P&gt;Anyway, I've tried your code and it does not work unfortunately. The log return a blank value for the variable. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 09:02:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805304#M65450</guid>
      <dc:creator>Nwinx1984</dc:creator>
      <dc:date>2021-05-05T09:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Load specific Excel sheet with variable name</title>
      <link>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805312#M65452</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/140849"&gt;@Nwinx1984&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I cannot replicate what is going wrong in your code, but maybe this post by&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/35867"&gt;@avinashelite&lt;/a&gt;&amp;nbsp;&amp;nbsp;can contain a solution for you. I have implemented this code several times for reading Excel files.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/t5/Documents/Loading-Multiple-Excel-Sheets-Dynamically-along-with-file-name/ta-p/1481095" target="_blank"&gt;https://community.qlik.com/t5/Documents/Loading-Multiple-Excel-Sheets-Dynamically-along-with-file-name/ta-p/1481095&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards Eddie&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 09:20:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1805312#M65452</guid>
      <dc:creator>eddie_wagt</dc:creator>
      <dc:date>2021-05-05T09:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: Load specific Excel sheet with variable name</title>
      <link>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1806459#M65594</link>
      <description>&lt;P&gt;Alright, thank you everyone for helping! I spent some time trying to use an ODBC connection to load the Excel file, but I encountered technical problems in my organization so I could not really test it.&lt;/P&gt;&lt;P&gt;Nevertheless, I kept on modifying the code and discovered that the problem was "FileBaseName()" which was not returning anything and therefore the variable vSheetName remained empty.&lt;/P&gt;&lt;P&gt;The solution was to replace FileBaseName() with File, the variable I was already using for the For loop. Final working code below.&lt;/P&gt;&lt;P&gt;-------------------------&lt;/P&gt;&lt;P&gt;For each File in FileList('[lib://xxx/xxx Statistic - *.xlsx]')&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;let vSheetName = left(right(subfield('$(File)', ' - ', -1), 8), 3) &amp;amp; ' ' &amp;amp; left(subfield('$(File)', ' - ', -1), 4);&amp;nbsp;&lt;BR /&gt;TRACE $(vSheetName);&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Table:&lt;BR /&gt;LOAD *&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;From $(File)&lt;BR /&gt;(ooxml, embedded labels, table is '$(vSheetName)';&lt;/P&gt;&lt;P&gt;NEXT File;&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 07:14:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Load-specific-Excel-sheet-with-variable-name/m-p/1806459#M65594</guid>
      <dc:creator>Nwinx1984</dc:creator>
      <dc:date>2021-05-10T07:14:13Z</dc:date>
    </item>
  </channel>
</rss>

