<?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 Rename field in loop store statement in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Rename-field-in-loop-store-statement/m-p/2502523#M103468</link>
    <description>&lt;P&gt;I have a folder that contains several monthly .xlsx files.&amp;nbsp; Most of these files contain a field called "Grade Category".&amp;nbsp; In the newer months, this field is renamed to "Career Band/Level Category".&amp;nbsp; I am trying to create a process to loop through each of these files and rename the field if needed and store into a qvd.&amp;nbsp; The 2 processes are broken out below.&amp;nbsp; I've also included my script.&amp;nbsp; This script works fine for all of the files that contain "Grade Category".&amp;nbsp; Once it gets to a file where the field is&amp;nbsp;"Career Band/Level Category" I am getting an error stating 'FinalTable' is not found.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;Any suggestions on what I'm doing wrong? Thanks in advance!&lt;/P&gt;
&lt;P&gt;1. If the field in the file is called "Grade Category", rename it to&amp;nbsp;"Career Band/Level Category" and then store it into a qvd.&lt;/P&gt;
&lt;P&gt;2. If the field in the file is called "Career Band/Level Category", no renaming is necessary and the file can be stored into a qvd.&lt;/P&gt;
&lt;P&gt;My Script:&lt;/P&gt;
&lt;P&gt;// Define the source folder containing the raw files and the QVD target folder&lt;BR /&gt;LET vSourceFolder = 'lib:/.../'; &lt;BR /&gt;LET vTargetFolder = 'lib://.../';&lt;/P&gt;
&lt;P&gt;// Get a list of the files in the source folder&lt;BR /&gt;FOR Each vFile in FileList('$(vSourceFolder)*Global Audit Reports Active *.xlsx') &lt;BR /&gt;// Extract the file name without the extension&lt;BR /&gt;LET vFileName = SubField(vFile, '/', -1);&lt;BR /&gt;LET vFileBaseName = SubField(vFileName, '.', 1); // Remove the extension&lt;BR /&gt;&lt;BR /&gt;// Construct the QVD file name &lt;BR /&gt;LET vQvdFileName = '$(vTargetFolder)' &amp;amp; '$(vFileBaseName).qvd';&lt;BR /&gt;&lt;BR /&gt;// Debugging: Trace the generated QVD file name&lt;BR /&gt;TRACE Checking QVD file: $(vQvdFileName);&lt;/P&gt;
&lt;P&gt;// Check if the QVD already exists&lt;BR /&gt;IF NOT IsNull(FileSize('$(vQvdFileName)')) THEN&lt;BR /&gt;// If FileSize returns a number, that means the file exists&lt;BR /&gt;TRACE QVD [$(vQvdFileName)] already exists, skipping loading of [$(vFile)];&lt;BR /&gt;ELSE&lt;BR /&gt;// Load the data from the Excel file into a temporary table&lt;BR /&gt;TempTable:&lt;BR /&gt;LOAD &lt;BR /&gt;*&lt;BR /&gt;FROM [$(vFile)]&lt;BR /&gt;(ooxml, embedded labels, table is [RPT033]);&lt;BR /&gt;&lt;BR /&gt;// Check for the existence of the Career Band/Level Category field using FieldIndex &lt;BR /&gt;LET vFieldExists = FieldNumber('Career Band/Level Category', 'TempTable');&lt;BR /&gt;TRACE Checking vFieldExists: $(vFieldExists);&lt;/P&gt;
&lt;P&gt;// Create the final table based on the field existence&lt;BR /&gt;IF vFieldExists &amp;gt; 0 THEN&lt;BR /&gt;FinalTable:&lt;BR /&gt;LOAD &lt;BR /&gt;*&lt;BR /&gt;RESIDENT TempTable;&lt;BR /&gt;ELSE&lt;BR /&gt;FinalTable:&lt;BR /&gt;LOAD &lt;BR /&gt;*,&lt;BR /&gt;"Grade Category" AS "Career Band/Level Category"&lt;BR /&gt;RESIDENT TempTable;&lt;BR /&gt;Drop Field "Grade Category" from FinalTable;&lt;BR /&gt;ENDIF;&lt;/P&gt;
&lt;P&gt;// Store the data from the final table into QVD&lt;BR /&gt;STORE FinalTable INTO [$(vQvdFileName)];&lt;BR /&gt;&lt;BR /&gt;// Drop the temporary tables to free up memory&lt;BR /&gt;DROP TABLE TempTable;&lt;BR /&gt;DROP TABLE FinalTable;&lt;BR /&gt;ENDIF&lt;BR /&gt;NEXT vFile;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;DIV class=""&gt;QVD [lib://.../Global Audit Reports Active 2024-11.qvd] already exists, skipping loading of [lib://.../Global Audit Reports Active 2024-11.xlsx] Checking QVD file: lib://.../Global Audit Reports Active 2024-12.qvd&lt;/DIV&gt;
&lt;DIV class=""&gt;TempTable &amp;lt;&amp;lt; RPT033&lt;/DIV&gt;
&lt;DIV class=""&gt;Lines fetched: 40,826 Checking vFieldExists: 18 TempTable &amp;lt;&amp;lt; TempTable&lt;/DIV&gt;
&lt;DIV class=""&gt;Lines fetched: 81,652&lt;/DIV&gt;
&lt;DIV class="empty undefined"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="headline edc_error"&gt;The following error occurred:&lt;/DIV&gt;
&lt;DIV class="edc_error"&gt;Table 'FinalTable' not found&lt;/DIV&gt;
&lt;DIV class="empty edc_error"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="headline edc_error"&gt;The error occurred here:&lt;/DIV&gt;
&lt;DIV class="edc_error"&gt;STORE FinalTable INTO [lib://.../Global Audit Reports Active 2024-12.qvd]&lt;/DIV&gt;
&lt;DIV class="empty undefined"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="headline undefined"&gt;Data has not been loaded. Please correct the error and try loading again.&lt;/DIV&gt;</description>
    <pubDate>Wed, 22 Jan 2025 19:25:34 GMT</pubDate>
    <dc:creator>Hannah_M</dc:creator>
    <dc:date>2025-01-22T19:25:34Z</dc:date>
    <item>
      <title>Rename field in loop store statement</title>
      <link>https://community.qlik.com/t5/App-Development/Rename-field-in-loop-store-statement/m-p/2502523#M103468</link>
      <description>&lt;P&gt;I have a folder that contains several monthly .xlsx files.&amp;nbsp; Most of these files contain a field called "Grade Category".&amp;nbsp; In the newer months, this field is renamed to "Career Band/Level Category".&amp;nbsp; I am trying to create a process to loop through each of these files and rename the field if needed and store into a qvd.&amp;nbsp; The 2 processes are broken out below.&amp;nbsp; I've also included my script.&amp;nbsp; This script works fine for all of the files that contain "Grade Category".&amp;nbsp; Once it gets to a file where the field is&amp;nbsp;"Career Band/Level Category" I am getting an error stating 'FinalTable' is not found.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;Any suggestions on what I'm doing wrong? Thanks in advance!&lt;/P&gt;
&lt;P&gt;1. If the field in the file is called "Grade Category", rename it to&amp;nbsp;"Career Band/Level Category" and then store it into a qvd.&lt;/P&gt;
&lt;P&gt;2. If the field in the file is called "Career Band/Level Category", no renaming is necessary and the file can be stored into a qvd.&lt;/P&gt;
&lt;P&gt;My Script:&lt;/P&gt;
&lt;P&gt;// Define the source folder containing the raw files and the QVD target folder&lt;BR /&gt;LET vSourceFolder = 'lib:/.../'; &lt;BR /&gt;LET vTargetFolder = 'lib://.../';&lt;/P&gt;
&lt;P&gt;// Get a list of the files in the source folder&lt;BR /&gt;FOR Each vFile in FileList('$(vSourceFolder)*Global Audit Reports Active *.xlsx') &lt;BR /&gt;// Extract the file name without the extension&lt;BR /&gt;LET vFileName = SubField(vFile, '/', -1);&lt;BR /&gt;LET vFileBaseName = SubField(vFileName, '.', 1); // Remove the extension&lt;BR /&gt;&lt;BR /&gt;// Construct the QVD file name &lt;BR /&gt;LET vQvdFileName = '$(vTargetFolder)' &amp;amp; '$(vFileBaseName).qvd';&lt;BR /&gt;&lt;BR /&gt;// Debugging: Trace the generated QVD file name&lt;BR /&gt;TRACE Checking QVD file: $(vQvdFileName);&lt;/P&gt;
&lt;P&gt;// Check if the QVD already exists&lt;BR /&gt;IF NOT IsNull(FileSize('$(vQvdFileName)')) THEN&lt;BR /&gt;// If FileSize returns a number, that means the file exists&lt;BR /&gt;TRACE QVD [$(vQvdFileName)] already exists, skipping loading of [$(vFile)];&lt;BR /&gt;ELSE&lt;BR /&gt;// Load the data from the Excel file into a temporary table&lt;BR /&gt;TempTable:&lt;BR /&gt;LOAD &lt;BR /&gt;*&lt;BR /&gt;FROM [$(vFile)]&lt;BR /&gt;(ooxml, embedded labels, table is [RPT033]);&lt;BR /&gt;&lt;BR /&gt;// Check for the existence of the Career Band/Level Category field using FieldIndex &lt;BR /&gt;LET vFieldExists = FieldNumber('Career Band/Level Category', 'TempTable');&lt;BR /&gt;TRACE Checking vFieldExists: $(vFieldExists);&lt;/P&gt;
&lt;P&gt;// Create the final table based on the field existence&lt;BR /&gt;IF vFieldExists &amp;gt; 0 THEN&lt;BR /&gt;FinalTable:&lt;BR /&gt;LOAD &lt;BR /&gt;*&lt;BR /&gt;RESIDENT TempTable;&lt;BR /&gt;ELSE&lt;BR /&gt;FinalTable:&lt;BR /&gt;LOAD &lt;BR /&gt;*,&lt;BR /&gt;"Grade Category" AS "Career Band/Level Category"&lt;BR /&gt;RESIDENT TempTable;&lt;BR /&gt;Drop Field "Grade Category" from FinalTable;&lt;BR /&gt;ENDIF;&lt;/P&gt;
&lt;P&gt;// Store the data from the final table into QVD&lt;BR /&gt;STORE FinalTable INTO [$(vQvdFileName)];&lt;BR /&gt;&lt;BR /&gt;// Drop the temporary tables to free up memory&lt;BR /&gt;DROP TABLE TempTable;&lt;BR /&gt;DROP TABLE FinalTable;&lt;BR /&gt;ENDIF&lt;BR /&gt;NEXT vFile;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;DIV class=""&gt;QVD [lib://.../Global Audit Reports Active 2024-11.qvd] already exists, skipping loading of [lib://.../Global Audit Reports Active 2024-11.xlsx] Checking QVD file: lib://.../Global Audit Reports Active 2024-12.qvd&lt;/DIV&gt;
&lt;DIV class=""&gt;TempTable &amp;lt;&amp;lt; RPT033&lt;/DIV&gt;
&lt;DIV class=""&gt;Lines fetched: 40,826 Checking vFieldExists: 18 TempTable &amp;lt;&amp;lt; TempTable&lt;/DIV&gt;
&lt;DIV class=""&gt;Lines fetched: 81,652&lt;/DIV&gt;
&lt;DIV class="empty undefined"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="headline edc_error"&gt;The following error occurred:&lt;/DIV&gt;
&lt;DIV class="edc_error"&gt;Table 'FinalTable' not found&lt;/DIV&gt;
&lt;DIV class="empty edc_error"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="headline edc_error"&gt;The error occurred here:&lt;/DIV&gt;
&lt;DIV class="edc_error"&gt;STORE FinalTable INTO [lib://.../Global Audit Reports Active 2024-12.qvd]&lt;/DIV&gt;
&lt;DIV class="empty undefined"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="headline undefined"&gt;Data has not been loaded. Please correct the error and try loading again.&lt;/DIV&gt;</description>
      <pubDate>Wed, 22 Jan 2025 19:25:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Rename-field-in-loop-store-statement/m-p/2502523#M103468</guid>
      <dc:creator>Hannah_M</dc:creator>
      <dc:date>2025-01-22T19:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Rename field in loop store statement</title>
      <link>https://community.qlik.com/t5/App-Development/Rename-field-in-loop-store-statement/m-p/2502533#M103469</link>
      <description>&lt;P&gt;may be you need a NOCONCATENATE when you load the FinalTable from TempTable&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 21:16:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Rename-field-in-loop-store-statement/m-p/2502533#M103469</guid>
      <dc:creator>maxgro</dc:creator>
      <dc:date>2025-01-22T21:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Rename field in loop store statement</title>
      <link>https://community.qlik.com/t5/App-Development/Rename-field-in-loop-store-statement/m-p/2502534#M103470</link>
      <description>&lt;P&gt;I think you may be overthinking it. I would think using just an ALIAS statement would work. The Alias statement will automatically rename the field if it exists.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alias&amp;nbsp;&lt;SPAN&gt;"Career Band/Level Category" as&amp;nbsp;"Grade Category";&lt;BR /&gt;LOAD * From lib://source/*.xlsx;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can adapt this to a For loop if you actually need to read and store each file -- but I was guessing maybe you were just doing that for the field rename.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;See&amp;nbsp;&lt;A href="https://qlikviewcookbook.com/2018/12/loading-varying-column-names/" target="_blank" rel="noopener"&gt;https://qlikviewcookbook.com/2018/12/loading-varying-column-names/&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;-Rob&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 19:20:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Rename-field-in-loop-store-statement/m-p/2502534#M103470</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2025-01-23T19:20:29Z</dc:date>
    </item>
  </channel>
</rss>

