<?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: Deploying identical transformations to series of fields within a load statement in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Deploying-identical-transformations-to-series-of-fields-within-a/m-p/1811139#M66114</link>
    <description>&lt;P&gt;I think you are on the right track with the variable approach.&amp;nbsp; &amp;nbsp;I might consider building with a LOAD statement instead and then transferring into variables. Like this:&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;Set&lt;/SPAN&gt; vNewline = ',' &amp;amp; chr(10);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Transforms:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;LOAD&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp; Concat&lt;/SPAN&gt;(&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; 'sum([' &amp;amp; &lt;SPAN class="s2"&gt;infield&lt;/SPAN&gt; &amp;amp; '_thismonth]) as [' &amp;amp; &lt;SPAN class="s2"&gt;infield&lt;/SPAN&gt; &amp;amp; '_todate]'&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; , &lt;SPAN class="s3"&gt;&lt;I&gt;$(vNewline)&lt;/I&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; ) &lt;SPAN class="s1"&gt;as&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;Transform_Todate&lt;/SPAN&gt;,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp; Concat&lt;/SPAN&gt;(&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; 'Avg([' &amp;amp; &lt;SPAN class="s2"&gt;infield&lt;/SPAN&gt; &amp;amp; '_count]) as [' &amp;amp; &lt;SPAN class="s2"&gt;infield&lt;/SPAN&gt; &amp;amp; '_Average_Count]'&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; , &lt;SPAN class="s3"&gt;&lt;I&gt;$(vNewline)&lt;/I&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; ) &lt;SPAN class="s1"&gt;as&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;Transform_AvgCount&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;LOAD&lt;/SPAN&gt; * &lt;SPAN class="s1"&gt;Inline&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;[&lt;BR /&gt;infield&lt;BR /&gt;gears&lt;BR /&gt;widgets&lt;BR /&gt;]&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;Let&lt;/SPAN&gt; vTransformTodate = &lt;SPAN class="s1"&gt;peek&lt;/SPAN&gt;('Transform_Todate');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;Let&lt;/SPAN&gt; vTransformAvgCount = &lt;SPAN class="s1"&gt;peek&lt;/SPAN&gt;('Transform_AvgCount');&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Data:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;LOAD&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s3"&gt;&lt;I&gt;&amp;nbsp; $(vTransformTodate)&lt;/I&gt;&lt;/SPAN&gt;,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s3"&gt;&lt;I&gt;&amp;nbsp; $(vTransformAvgCount)&lt;/I&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;Resident&lt;/SPAN&gt; gearsandwidgets; &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;-Rob&lt;BR /&gt;&lt;A href="http://masterssummit.com" target="_blank"&gt;http://masterssummit.com&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://qlikviewcookbook.com" target="_blank"&gt;http://qlikviewcookbook.com&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://www.easyqlik.com" target="_blank"&gt;http://www.easyqlik.com&lt;/A&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 27 May 2021 17:28:09 GMT</pubDate>
    <dc:creator>rwunderlich</dc:creator>
    <dc:date>2021-05-27T17:28:09Z</dc:date>
    <item>
      <title>Deploying identical transformations to series of fields within a load statement</title>
      <link>https://community.qlik.com/t5/App-Development/Deploying-identical-transformations-to-series-of-fields-within-a/m-p/1811087#M66110</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a series of fields that are transformed multiple times, always in identical ways, over the course of a load script. Some transformations simple, some a little more complex, but always identical. For example, the first one is a simple sum, similar to this:&lt;/P&gt;&lt;P&gt;load&lt;BR /&gt;&amp;nbsp; &amp;nbsp; id,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; sum(gears_thismonth) as gears_todate,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; sum(widgets_thismonth) as widgets_todate&lt;BR /&gt;resident gearsandwidgets&lt;BR /&gt;&amp;nbsp; &amp;nbsp; group by id;&lt;/P&gt;&lt;P&gt;There are currently about 15 fields undergoing these transformations, and it's possible I'll add more. Editing some of the transformations is tedious and error-prone.&lt;/P&gt;&lt;P&gt;I've looked into &lt;A href="https://community.qlik.com/t5/New-to-Qlik-Sense/loop-inside-load-statement/td-p/1701834" target="_self"&gt;using a loop directly within a load statement&lt;/A&gt;&amp;nbsp;and &lt;A href="https://community.qlik.com/t5/QlikView-App-Dev/Calling-Subs-within-Loads-to-return-value/m-p/1305598" target="_self"&gt;calling a subroutine within a load statement&lt;/A&gt;&amp;nbsp;(not as good as using a loop but would still reduce the amount of copy-pasting necessary) and it looks like neither are possible.&lt;/P&gt;&lt;P&gt;The closest I can think is to define the bulk of the script block as a variable - something like:&lt;/P&gt;&lt;P&gt;let transformations = '';&lt;BR /&gt;for each field in 'gears', 'widgets'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; let transformations = '$(transformations)' &amp;amp; ',' &amp;amp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 'sum($(field)_thismonth) as $(field)_todate'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ;&lt;BR /&gt;next&lt;BR /&gt;load&lt;BR /&gt;&amp;nbsp; &amp;nbsp; id&lt;BR /&gt;&amp;nbsp; &amp;nbsp; $(trasformations)&lt;BR /&gt;resident gearsandwidgets&lt;BR /&gt;&amp;nbsp; &amp;nbsp; group by id;&lt;/P&gt;&lt;P&gt;(Haven't tested this solution yet.)&lt;/P&gt;&lt;P&gt;Has anyone else run into this issue and come up with a sustainable solution?&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 14:23:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Deploying-identical-transformations-to-series-of-fields-within-a/m-p/1811087#M66110</guid>
      <dc:creator>lwestmaas</dc:creator>
      <dc:date>2021-05-27T14:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Deploying identical transformations to series of fields within a load statement</title>
      <link>https://community.qlik.com/t5/App-Development/Deploying-identical-transformations-to-series-of-fields-within-a/m-p/1811139#M66114</link>
      <description>&lt;P&gt;I think you are on the right track with the variable approach.&amp;nbsp; &amp;nbsp;I might consider building with a LOAD statement instead and then transferring into variables. Like this:&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;Set&lt;/SPAN&gt; vNewline = ',' &amp;amp; chr(10);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Transforms:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;LOAD&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp; Concat&lt;/SPAN&gt;(&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; 'sum([' &amp;amp; &lt;SPAN class="s2"&gt;infield&lt;/SPAN&gt; &amp;amp; '_thismonth]) as [' &amp;amp; &lt;SPAN class="s2"&gt;infield&lt;/SPAN&gt; &amp;amp; '_todate]'&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; , &lt;SPAN class="s3"&gt;&lt;I&gt;$(vNewline)&lt;/I&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; ) &lt;SPAN class="s1"&gt;as&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;Transform_Todate&lt;/SPAN&gt;,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp; Concat&lt;/SPAN&gt;(&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; 'Avg([' &amp;amp; &lt;SPAN class="s2"&gt;infield&lt;/SPAN&gt; &amp;amp; '_count]) as [' &amp;amp; &lt;SPAN class="s2"&gt;infield&lt;/SPAN&gt; &amp;amp; '_Average_Count]'&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; , &lt;SPAN class="s3"&gt;&lt;I&gt;$(vNewline)&lt;/I&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; ) &lt;SPAN class="s1"&gt;as&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;Transform_AvgCount&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;LOAD&lt;/SPAN&gt; * &lt;SPAN class="s1"&gt;Inline&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;[&lt;BR /&gt;infield&lt;BR /&gt;gears&lt;BR /&gt;widgets&lt;BR /&gt;]&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;Let&lt;/SPAN&gt; vTransformTodate = &lt;SPAN class="s1"&gt;peek&lt;/SPAN&gt;('Transform_Todate');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;Let&lt;/SPAN&gt; vTransformAvgCount = &lt;SPAN class="s1"&gt;peek&lt;/SPAN&gt;('Transform_AvgCount');&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Data:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;LOAD&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s3"&gt;&lt;I&gt;&amp;nbsp; $(vTransformTodate)&lt;/I&gt;&lt;/SPAN&gt;,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s3"&gt;&lt;I&gt;&amp;nbsp; $(vTransformAvgCount)&lt;/I&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="s1"&gt;Resident&lt;/SPAN&gt; gearsandwidgets; &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="Apple-converted-space"&gt;-Rob&lt;BR /&gt;&lt;A href="http://masterssummit.com" target="_blank"&gt;http://masterssummit.com&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://qlikviewcookbook.com" target="_blank"&gt;http://qlikviewcookbook.com&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://www.easyqlik.com" target="_blank"&gt;http://www.easyqlik.com&lt;/A&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 17:28:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Deploying-identical-transformations-to-series-of-fields-within-a/m-p/1811139#M66114</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2021-05-27T17:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Deploying identical transformations to series of fields within a load statement</title>
      <link>https://community.qlik.com/t5/App-Development/Deploying-identical-transformations-to-series-of-fields-within-a/m-p/1811155#M66116</link>
      <description>&lt;P&gt;Thanks! This was a good push, and it seems to be working perfectly. It lets me centralize creation of each function in a single location, and for readability I like using the inline table to list out the fields over putting them in a loop.&lt;/P&gt;&lt;P&gt;Full sample pasted below. Note the third function "transform_complexrecords_todate" allows use of a loop (with variable "level") when actually called in my script. And I added another twist - a loop that autocreates each variable (starting with "for adds_and_transforms = 1" at bottom).&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Set newline = ',' &amp;amp; chr(10);
adds_and_transforms:
LOAD
	concat('sum('&amp;amp;infield&amp;amp;'_inmonth_store) as '&amp;amp;infield&amp;amp;'_todate_store',$(newline)) as transform_simplerecords_todate_store,
	concat(infield&amp;amp;'_inmonth_store',$(newline)) as add_simplerecords_inmonth_store,	
	concat(
		'if(previous(%key_'&amp;amp;chr(36)&amp;amp;'(level)_year)=%key_'&amp;amp;chr(36)&amp;amp;'(level)_year,
			peek(' &amp;amp; infield &amp;amp; '_todate_'&amp;amp;chr(36)&amp;amp;'(level)) + ' &amp;amp; infield &amp;amp; '_inmonth_store,
			' &amp;amp; infield &amp;amp; '_inmonth_store
		) as ' &amp;amp; infield &amp;amp; '_todate_'&amp;amp;chr(36)&amp;amp;'(level)'
	, $(newline)
	) as transform_complexrecords_todate
;
LOAD * Inline [
infield
gears
widgets
]
;

for adds_and_transforms = 1 to NoOfFields('adds_and_transforms')
	let add_or_transform_name = fieldname($(adds_and_transforms),'adds_and_transforms');
	let $(add_or_transform_name) = peek('$(add_or_transform_name)');
next
let adds_and_transforms = ;
let add_or_transform_name = ;

drop table adds_and_transforms;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 19:21:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Deploying-identical-transformations-to-series-of-fields-within-a/m-p/1811155#M66116</guid>
      <dc:creator>lwestmaas</dc:creator>
      <dc:date>2021-05-27T19:21:23Z</dc:date>
    </item>
  </channel>
</rss>

