<?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 Using fields and variables to rename fields during load in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142015#M21589</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="jive_text_macro jive_macro_quote" jivemacro="quote"&gt;&lt;BR /&gt;Anthony Deighton wrote:&lt;BR /&gt;... is that you can use a &lt;I&gt;mapping table&lt;/I&gt; to do the rename. &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;I understood the original post to say that in row 1, M_0 would be named March_2009 and in row 2 M_0 should be renamed November_2009. So it's not a straight RENAME of M_0 to the same name for all rows.&lt;/P&gt;&lt;P&gt;If I understand the question correctly, here's a possible solution. You didn't say if you want all the columns in the same table. If you want seperate tables, just pull out the CONCATENATE keyword in the load. I've attached an example qvw also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;tempdata:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;Ref, M_0, M_1, M_2, M_3, M_Offset, Year&lt;BR /&gt;1, 201, 301, 401, 501, 3, 2009&lt;BR /&gt;2, 202, 302, 402, 502, 11, 2009&lt;BR /&gt;3, 203, 303, 403, 503, 1, 2008&lt;BR /&gt;4, 204, 304, 404, 504, 12, 2009&lt;BR /&gt;]&lt;BR /&gt;;&lt;BR /&gt;idx:&lt;BR /&gt;LOAD DISTINCT&lt;BR /&gt; M_Offset as idx_offset,&lt;BR /&gt; Year as idx_year&lt;BR /&gt;RESIDENT tempdata&lt;BR /&gt;;&lt;BR /&gt;Sub loadCols (month, year)&lt;BR /&gt;LET basedate = MakeDate(year, month);&lt;BR /&gt;LET m0 = Date(basedate, 'MMMM_YYYY');&lt;BR /&gt;LET m1 = Date(AddMonths(basedate,1), 'MMMM_YYYY');&lt;BR /&gt;LET m2 = Date(AddMonths(basedate,2), 'MMMM_YYYY');&lt;BR /&gt;LET m3 = Date(AddMonths(basedate,3), 'MMMM_YYYY');&lt;BR /&gt;final:&lt;BR /&gt;$(CONCATENATE) LOAD&lt;BR /&gt; Ref,&lt;BR /&gt; M_0 as $(m0),&lt;BR /&gt; M_1 as $(m1),&lt;BR /&gt; M_2 as $(m2),&lt;BR /&gt; M_3 as $(m3)&lt;BR /&gt;RESIDENT tempdata&lt;BR /&gt;WHERE M_Offset = $(month) AND Year = $(year)&lt;BR /&gt;;&lt;BR /&gt;End Sub&lt;BR /&gt;SET CONCATENATE = ''; // No concat on first call&lt;BR /&gt;For i = 0 to NoOfRows('idx')-1&lt;BR /&gt; Call loadCols (peek('idx_offset', i, 'idx'), peek('idx_year', i, 'idx'))&lt;BR /&gt; SET CONCATENATE = 'CONCATENATE';&lt;BR /&gt;Next&lt;BR /&gt;DROP TABLES tempdata, idx;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;I think this will work for a reasonable number of rows.&lt;/P&gt;&lt;P&gt;-Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Apr 2009 07:08:25 GMT</pubDate>
    <dc:creator>rwunderlich</dc:creator>
    <dc:date>2009-04-22T07:08:25Z</dc:date>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142011#M21585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI&lt;/P&gt;&lt;P&gt;OK, I have a table with columns Ref, M_0, M_1, M_2, M_3, M_Offset and Year&lt;/P&gt;&lt;P&gt;I want to load the rows of the table with field names that are calculated from the M_offset value&lt;/P&gt;&lt;P&gt;i.e. if in the first row, M_Offset = 3, and Year = 2009 then I want to rename M_0 as March_2009, M_1 as April_2009, etc&lt;/P&gt;&lt;P&gt;The next row may have a different offset i.e. 11, in which case M_0 would become November_2009, M_1 = December_2009 and M_2 = January 2010&lt;/P&gt;&lt;P&gt;and so on&lt;/P&gt;&lt;P&gt;Has anyone any ideas?&lt;/P&gt;&lt;P&gt;I have tried using Load M_0 as if(M_offset = 3,March &amp;amp; Year,.........&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 02:52:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142011#M21585</guid>
      <dc:creator />
      <dc:date>2009-04-22T02:52:55Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142012#M21586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should be able to handle this using SQL commands in your Load statement. Something like this should work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;to_date(&lt;/B&gt;M_Offset || '/01/' || M_Year, 'MM/DD/YYYY') &lt;B&gt;As&lt;/B&gt; M_0,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;add_months (&lt;/B&gt;&lt;B&gt;to_date&lt;/B&gt;(M_Offset || '/01/' || M_Year, 'MM/DD/YYYY'), 1) &lt;B&gt;As&lt;/B&gt; M_1&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;Note this is Oracle code, I'm not sure if you would have to modify it if you were using TSQL.&lt;/P&gt;&lt;P&gt;You could use a to_char(..., 'MON YYYY') or something similar around the fields to get a string like in your example. If you keep the straight dates, you can format them in QlikView using:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Month (M_0) &amp;amp; ' ' &amp;amp; Year(M_0)&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 04:28:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142012#M21586</guid>
      <dc:creator />
      <dc:date>2009-04-22T04:28:54Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142013#M21587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to confirm, you want to change the column names on a row-by-row basis? How many rows are you talking about?&lt;/P&gt;&lt;P&gt;-Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 06:01:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142013#M21587</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2009-04-22T06:01:13Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142014#M21588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Take a look in the documentation at page 333 at the RENAME FIELD (and RENAME TABLE) script commands. These do what you would expect... rename fields and tables. Even COOLER, however, is that you can use a &lt;I&gt;mapping table&lt;/I&gt; to do the rename. So you do a MAPPING LOAD with all the "strangely named fields" and all the "english named fields" and do the translation automatically. And, if you're really good, you can use autogenerate() to automatically generate the mapping table, because the field names look to be pretty easy to map between "strange" and "english".&lt;/P&gt;&lt;P&gt;-A&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 06:22:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142014#M21588</guid>
      <dc:creator />
      <dc:date>2009-04-22T06:22:15Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142015#M21589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="jive_text_macro jive_macro_quote" jivemacro="quote"&gt;&lt;BR /&gt;Anthony Deighton wrote:&lt;BR /&gt;... is that you can use a &lt;I&gt;mapping table&lt;/I&gt; to do the rename. &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;I understood the original post to say that in row 1, M_0 would be named March_2009 and in row 2 M_0 should be renamed November_2009. So it's not a straight RENAME of M_0 to the same name for all rows.&lt;/P&gt;&lt;P&gt;If I understand the question correctly, here's a possible solution. You didn't say if you want all the columns in the same table. If you want seperate tables, just pull out the CONCATENATE keyword in the load. I've attached an example qvw also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;tempdata:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;Ref, M_0, M_1, M_2, M_3, M_Offset, Year&lt;BR /&gt;1, 201, 301, 401, 501, 3, 2009&lt;BR /&gt;2, 202, 302, 402, 502, 11, 2009&lt;BR /&gt;3, 203, 303, 403, 503, 1, 2008&lt;BR /&gt;4, 204, 304, 404, 504, 12, 2009&lt;BR /&gt;]&lt;BR /&gt;;&lt;BR /&gt;idx:&lt;BR /&gt;LOAD DISTINCT&lt;BR /&gt; M_Offset as idx_offset,&lt;BR /&gt; Year as idx_year&lt;BR /&gt;RESIDENT tempdata&lt;BR /&gt;;&lt;BR /&gt;Sub loadCols (month, year)&lt;BR /&gt;LET basedate = MakeDate(year, month);&lt;BR /&gt;LET m0 = Date(basedate, 'MMMM_YYYY');&lt;BR /&gt;LET m1 = Date(AddMonths(basedate,1), 'MMMM_YYYY');&lt;BR /&gt;LET m2 = Date(AddMonths(basedate,2), 'MMMM_YYYY');&lt;BR /&gt;LET m3 = Date(AddMonths(basedate,3), 'MMMM_YYYY');&lt;BR /&gt;final:&lt;BR /&gt;$(CONCATENATE) LOAD&lt;BR /&gt; Ref,&lt;BR /&gt; M_0 as $(m0),&lt;BR /&gt; M_1 as $(m1),&lt;BR /&gt; M_2 as $(m2),&lt;BR /&gt; M_3 as $(m3)&lt;BR /&gt;RESIDENT tempdata&lt;BR /&gt;WHERE M_Offset = $(month) AND Year = $(year)&lt;BR /&gt;;&lt;BR /&gt;End Sub&lt;BR /&gt;SET CONCATENATE = ''; // No concat on first call&lt;BR /&gt;For i = 0 to NoOfRows('idx')-1&lt;BR /&gt; Call loadCols (peek('idx_offset', i, 'idx'), peek('idx_year', i, 'idx'))&lt;BR /&gt; SET CONCATENATE = 'CONCATENATE';&lt;BR /&gt;Next&lt;BR /&gt;DROP TABLES tempdata, idx;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;I think this will work for a reasonable number of rows.&lt;/P&gt;&lt;P&gt;-Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Apr 2009 07:08:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142015#M21589</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2009-04-22T07:08:25Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142016#M21590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi NMiller&lt;/P&gt;&lt;P&gt;Thanks, but I'm not so expert as to convert Oracle code into the QV&lt;/P&gt;&lt;P&gt;I did solve the problem with "preconditioning" in excel, and I have some other options, so I may try this when I have time&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks agan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;;o)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Apr 2009 00:13:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142016#M21590</guid>
      <dc:creator />
      <dc:date>2009-04-24T00:13:10Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142017#M21591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob&lt;/P&gt;&lt;P&gt;- Yes&lt;/P&gt;&lt;P&gt;Start Position in Excel:&lt;/P&gt;&lt;P&gt;Column Headers:&lt;/P&gt;&lt;P&gt;Offset_Month, Year, M0, M1, M2, M3&lt;/P&gt;&lt;P&gt;Data&lt;/P&gt;&lt;P&gt;4,2009,1,2,3&lt;/P&gt;&lt;P&gt;3,2009,4,5,6&lt;/P&gt;&lt;P&gt;10,2009,7,8,9&lt;/P&gt;&lt;P&gt;To convert to:&lt;/P&gt;&lt;P&gt;Headers:&lt;/P&gt;&lt;P&gt;Jan_2009,Feb_2009,Mar_2009,Apr_2009,May_2009,Jun_2009,Jul_2009,Aug_2009,Sep_2009,Oct_2009,Nov_2009,Dec_2009,Jan_2010&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;0,0,0,1,2,3,0,0,0,0,0,0,0&lt;/P&gt;&lt;P&gt;0,0,4,5,6,0,0,0,0,0,0,0,0&lt;/P&gt;&lt;P&gt;0,0,0,0,0,0,0,0,0,0,7,8,9&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- I am talking about less than 100 rows...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":monkey_face:"&gt;🐵&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Apr 2009 00:21:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142017#M21591</guid>
      <dc:creator />
      <dc:date>2009-04-24T00:21:37Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142018#M21592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmmm...&lt;/P&gt;&lt;P&gt;Sounds good, I'll start with the mapping load and carry on&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Apr 2009 00:24:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142018#M21592</guid>
      <dc:creator />
      <dc:date>2009-04-24T00:24:24Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142019#M21593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yup! Works! - does exactly what I wanted&lt;/P&gt;&lt;P&gt;but what to do for 100 rows - .....?.......!&lt;/P&gt;&lt;P&gt;I'll apply some engine newity this end&lt;/P&gt;&lt;P&gt;Ta!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Apr 2009 00:46:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142019#M21593</guid>
      <dc:creator />
      <dc:date>2009-04-24T00:46:56Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142020#M21594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, as this is only for a 12 month rolling forecast, I oly need to go to M_12 so Not so bad!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Apr 2009 00:49:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142020#M21594</guid>
      <dc:creator />
      <dc:date>2009-04-24T00:49:39Z</dc:date>
    </item>
    <item>
      <title>Using fields and variables to rename fields during load</title>
      <link>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142021#M21595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="jive_text_macro jive_macro_quote" jivemacro="quote"&gt;&lt;BR /&gt;khetienne wrote:&lt;BR /&gt;Yup! Works! - does exactly what I wanted&lt;BR /&gt; &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;Which suggestion worked?&lt;/P&gt;&lt;P&gt;-Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Apr 2009 01:20:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-fields-and-variables-to-rename-fields-during-load/m-p/142021#M21595</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2009-04-24T01:20:43Z</dc:date>
    </item>
  </channel>
</rss>

