<?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 loop causing data to double in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2003414#M83086</link>
    <description>&lt;P&gt;The loop should in your case be defined with:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF00FF"&gt;for it=0 to $(vNumRows)-1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;because the peek-index to access any rows starts by 0. For the cause with the duplicates look for the hints from &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/2751"&gt;@vinieme12&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;- Marcus&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Nov 2022 08:41:12 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2022-11-11T08:41:12Z</dc:date>
    <item>
      <title>For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002458#M83026</link>
      <description>&lt;P&gt;ReadingsTemp seems to be duplicating my data for each loop. I've pasted my code below. There isn't an error but it seems to be stuck in an infinite loop.&lt;/P&gt;
&lt;P&gt;Please advise!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BenjaminCoe1440_0-1668002936152.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/93262iAA157E9AF9F67786/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BenjaminCoe1440_0-1668002936152.png" alt="BenjaminCoe1440_0-1668002936152.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[ClientList]:
LOAD * INLINE [
AccountName, AccountId
'Company A', 'e4741f2f-#########-######'
'Company B', '4c3d8138-#########-######'

];
let vNumRows=NoOfRows('ClientList');


[MetRefTemp]:
LOAD * INLINE [
      AccNam,AccountId,MeterReference
];


for it=0 to $(vNumRows)
let vAcc=peek('AccountId',$(it),'ClientList');
let vAccName=peek('AccountName',$(it),'ClientList');

load *
resident [MetRefTemp];

Concatenate
  LOAD distinct 
      D365AccName AS AccNam
      ,AccountId 
      , MeterReference
  RESIDENT [DynamicsAccounts]
  WHERE (AccountId = '$(vAcc)');
 next; 

// Get readings from meter references in MetRefTemp table
let vMeterRows=NoOfRows('MetRefTemp');

[ReadingsTemp]:
LOAD * INLINE [
      MeterReference, ReadingsID, ReadingDateTime, RptTime, Value_Amount
];

for  it = 0 to $(vMeterRows)
let vMet=peek('MeterReference',$(it),'MetRefTemp');

load *
resident [ReadingsTemp];

concatenate 

load 
	MeterReference
    ,ReadingsID
    ,ReadingDateTime
    ,RptTime
    ,Value_Amount
resident [ENMATReadings]
where (MeterReference='$(vMet)');
next;


left join(ReadingsTemp)
load * Resident MetRefTemp;


for it=0 to $(vNumRows)
let vAccName=peek('AccountName',$(it),'ClientList');

[TempLoad]:
NoConcatenate
load * 
resident [ReadingsTemp]
where (AccNam='$(vAccName)');
store [TempLoad] into [lib://Admin - Data Loaders:DataFiles/metersdist_$(vAccName).qvd](qvd);
drop table [TempLoad];
next;




&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 14:11:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002458#M83026</guid>
      <dc:creator>BenjaminCoe1440</dc:creator>
      <dc:date>2022-11-09T14:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002475#M83028</link>
      <description>&lt;P&gt;use trace command to check which no of loop is going on..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 14:23:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002475#M83028</guid>
      <dc:creator>PrashantSangle</dc:creator>
      <dc:date>2022-11-09T14:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002478#M83029</link>
      <description>&lt;P&gt;Please elaborate. I'm not sure where I would use the trace command in this context.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 14:26:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002478#M83029</guid>
      <dc:creator>BenjaminCoe1440</dc:creator>
      <dc:date>2022-11-09T14:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002487#M83030</link>
      <description>&lt;P&gt;&lt;A href="https://help.qlik.com/en-US/sense/August2022/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Trace.htm" target="_blank"&gt;https://help.qlik.com/en-US/sense/August2022/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Trace.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;check how to use trace.&lt;/P&gt;
&lt;P&gt;so if you want to see in your script which no of loops is running or what is value of variable during load time then you can use trace.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[ClientList]:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;AccountName, AccountId&lt;BR /&gt;'Company A', 'e4741f2f-#########-######'&lt;BR /&gt;'Company B', '4c3d8138-#########-######'&lt;/P&gt;
&lt;P&gt;];&lt;BR /&gt;let vNumRows=NoOfRows('ClientList');&lt;/P&gt;
&lt;P&gt;trace $(vNumRows);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;[MetRefTemp]:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;AccNam,AccountId,MeterReference&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;for it=0 to $(vNumRows)&lt;BR /&gt;let vAcc=peek('AccountId',$(it),'ClientList');&lt;BR /&gt;let vAccName=peek('AccountName',$(it),'ClientList');&lt;/P&gt;
&lt;P&gt;trace $(it);&lt;/P&gt;
&lt;P&gt;load *&lt;BR /&gt;resident [MetRefTemp];&lt;/P&gt;
&lt;P&gt;Concatenate&lt;BR /&gt;LOAD distinct &lt;BR /&gt;D365AccName AS AccNam&lt;BR /&gt;,AccountId &lt;BR /&gt;, MeterReference&lt;BR /&gt;RESIDENT [DynamicsAccounts]&lt;BR /&gt;WHERE (AccountId = '$(vAcc)');&lt;BR /&gt;next;&lt;/P&gt;
&lt;P&gt;// Get readings from meter references in MetRefTemp table&lt;BR /&gt;let vMeterRows=NoOfRows('MetRefTemp');&lt;/P&gt;
&lt;P&gt;[ReadingsTemp]:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;MeterReference, ReadingsID, ReadingDateTime, RptTime, Value_Amount&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;for it = 0 to $(vMeterRows)&lt;BR /&gt;let vMet=peek('MeterReference',$(it),'MetRefTemp');&lt;/P&gt;
&lt;P&gt;trace $(it);&lt;/P&gt;
&lt;P&gt;load *&lt;BR /&gt;resident [ReadingsTemp];&lt;/P&gt;
&lt;P&gt;concatenate&lt;/P&gt;
&lt;P&gt;load &lt;BR /&gt;MeterReference&lt;BR /&gt;,ReadingsID&lt;BR /&gt;,ReadingDateTime&lt;BR /&gt;,RptTime&lt;BR /&gt;,Value_Amount&lt;BR /&gt;resident [ENMATReadings]&lt;BR /&gt;where (MeterReference='$(vMet)');&lt;BR /&gt;next;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;left join(ReadingsTemp)&lt;BR /&gt;load * Resident MetRefTemp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;for it=0 to $(vNumRows)&lt;BR /&gt;let vAccName=peek('AccountName',$(it),'ClientList');&lt;/P&gt;
&lt;P&gt;[TempLoad]:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;load * &lt;BR /&gt;resident [ReadingsTemp]&lt;BR /&gt;where (AccNam='$(vAccName)');&lt;BR /&gt;store [TempLoad] into [lib://Admin - Data Loaders:DataFiles/metersdist_$(vAccName).qvd](qvd);&lt;BR /&gt;drop table [TempLoad];&lt;BR /&gt;next;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added trace in most of place. You can modify as per your need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Prashant Sangle&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 14:33:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002487#M83030</guid>
      <dc:creator>PrashantSangle</dc:creator>
      <dc:date>2022-11-09T14:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002513#M83032</link>
      <description>&lt;P&gt;There are multiple issues within your approach, for example running to often through the loop because noofrows('ClientList') is 2 but your loop goes from 0 to 2 which are 3 iterations (it will later cause an empty variable and load-errors).&lt;/P&gt;
&lt;P&gt;More important is that you didn't specify to which table you want to apply the concatenate - it should be always explicitly set like you did by the join, means: concatenate(TableName) because without it the next table above is taken and I think that's the wrong one.&lt;/P&gt;
&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 15:06:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002513#M83032</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2022-11-09T15:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002945#M83056</link>
      <description>&lt;P&gt;&lt;FONT size="2"&gt;Thank Marcus.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Right, so, &lt;U&gt;&lt;STRONG&gt;issue No1:&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;FONT size="2"&gt;noofrows('ClientList') is 2 but your loop goes from 0 to 2 which are 3 iterations (it will later cause an empty variable and load-errors&lt;/FONT&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Using &lt;FONT color="#FF00FF"&gt;for it=0 to $(vNumRows)&lt;/FONT&gt; would give me 3 iterations, so would&amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#FF00FF"&gt;for it=1 to $(vNumRows)&lt;/FONT&gt;&lt;FONT color="#000000"&gt; give me the required 2 rows?&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;Or should it be something more like &lt;FONT color="#FF00FF"&gt;for it=0 to $(vNumRows)-1&lt;/FONT&gt; , for example?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;FONT size="2"&gt;Issue no2:&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;FONT size="2"&gt; you didn't specify to which table you want to apply the concatenate - it should be always explicitly set like you did by the join, means: concatenate(TableName) because without it the next table above is taken and I think that's the wrong one.&lt;/FONT&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Unfortunately, the suggested solution didn't fix my issue. I still have a loop which doubles the number of lines for each iteration. &lt;STRONG&gt;vMeterRows&lt;/STRONG&gt; has 95 rows to iterate over. I think I've isolated the bug to this loop.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;What I'm trying to do is use the field MeterReference to identify the name of the company (AccName) for that individual meter (left join at the bottom). I can then use the AccountName to split into qvd files of readings for that company.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;FONT size="2"&gt;MetRefTemp table&lt;/FONT&gt;&lt;/U&gt;&lt;/P&gt;
&lt;TABLE style="height: 40PX; width: 55%;" border="1" width="55%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;AccNam&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;AccountId&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;STRONG&gt;MeterReference&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Company A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;e4741f2f-#########-######&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;METER A&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Company A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;e4741f2f-#########-######&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;METER B&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Company B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;SPAN&gt;4c3d8138-#########-######&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;METER ZZZZ&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;What ENMATReadings is pulling through is;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="20%" height="27px"&gt;&lt;STRONG&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;MeterReference&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;STRONG&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;ReadingsID&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;STRONG&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;ReadingDateTime&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;STRONG&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;RptTime&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;STRONG&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Value_Amount (kWh)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;METER A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;0001A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;10/10/2022 09:00&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;09:00&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="25px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;95461.05&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;METER B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;0002A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;10/10/2022 09:00&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="49px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;09:00&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="25px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;95462&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="25px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;METER ZZZZ&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;B0001T&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;11/10/2022 09:30&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="27px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;09:30&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="20%" height="25px"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;94111&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;// Get readings from meter references in MetRefTemp table
let vMeterRows=NoOfRows('MetRefTemp');

[ReadingsTemp]:
LOAD * INLINE [
      MeterReference, ReadingsID, ReadingDateTime, RptTime, Value_Amount
];

for  it = 0 to $(vMeterRows)
let vMet=peek('MeterReference',$(it),'MetRefTemp');

trace $(it);

load *
resident [ReadingsTemp];

concatenate(ReadingsTemp)

load 
	MeterReference
    ,ReadingsID
    ,ReadingDateTime
    ,RptTime
    ,Value_Amount
resident [ENMATReadings]
where (MeterReference='$(vMet)');
next;

left join(ReadingsTemp)
load * Resident MetRefTemp;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 10:34:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2002945#M83056</guid>
      <dc:creator>BenjaminCoe1440</dc:creator>
      <dc:date>2022-11-10T10:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2003338#M83076</link>
      <description>&lt;P&gt;You are actually&amp;nbsp; loading the Existing table for each row&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[ClientList]:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;AccountName, AccountId&lt;BR /&gt;'Company A', 'e4741f2f-#########-######'&lt;BR /&gt;'Company B', '4c3d8138-#########-######'&lt;/P&gt;
&lt;P&gt;];&lt;BR /&gt;let vNumRows=NoOfRows('ClientList');&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;[MetRefTemp]:&lt;/FONT&gt;&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;AccNam,AccountId,MeterReference&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;for it=0 to $(vNumRows)&lt;BR /&gt;let vAcc=peek('AccountId',$(it),'ClientList');&lt;BR /&gt;let vAccName=peek('AccountName',$(it),'ClientList');&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;//*&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;This block is causing the duplication,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;You are loading the same table you want to concatenate the data&lt;STRONG&gt; to within the loop!!&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;this is what is happening&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;at&amp;nbsp; n = 0 You load filter&amp;nbsp; companyA&amp;nbsp; &amp;nbsp;and append to&lt;STRONG&gt; empty&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;table&lt;/STRONG&gt; [&lt;SPAN&gt;MetRefTemp&amp;nbsp;]&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;when &lt;STRONG&gt;n =1,&lt;/STRONG&gt; load resident [MetRefTemp&amp;nbsp;] &lt;STRONG&gt;which already has companyA&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;and Concatenate&amp;nbsp;&lt;STRONG&gt;companyB&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;now&amp;nbsp; MetRefTemp&amp;nbsp; &amp;nbsp; companyA&amp;nbsp; +&amp;nbsp; (n=1&amp;nbsp; companyA+companyB)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;when n =2&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&lt;STRONG&gt;now&amp;nbsp; MetRefTemp&amp;nbsp; &amp;nbsp; companyA&amp;nbsp; +&amp;nbsp; &amp;nbsp; ( companyA&amp;nbsp; +&amp;nbsp; (n=1&amp;nbsp; companyA+companyB) ) + companyC&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&lt;STRONG&gt;and so on&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;&lt;STRONG&gt;*//&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;load *&lt;BR /&gt;resident [MetRefTemp];&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Concatenate(&lt;SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;MetRefTemp)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;LOAD distinct &lt;BR /&gt;D365AccName AS AccNam&lt;BR /&gt;,AccountId &lt;BR /&gt;, MeterReference&lt;BR /&gt;RESIDENT [DynamicsAccounts]&lt;BR /&gt;WHERE (AccountId = '$(vAcc)');&lt;BR /&gt;next;&lt;/P&gt;
&lt;P&gt;// Get readings from meter references in MetRefTemp table&lt;BR /&gt;let vMeterRows=NoOfRows('MetRefTemp');&lt;/P&gt;
&lt;P&gt;[ReadingsTemp]:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;MeterReference, ReadingsID, ReadingDateTime, RptTime, Value_Amount&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;for it = 0 to $(vMeterRows)&lt;BR /&gt;let vMet=peek('MeterReference',$(it),'MetRefTemp');&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;&lt;FONT color="#FF0000"&gt;load *&lt;/FONT&gt;&lt;/STRIKE&gt;&lt;BR /&gt;&lt;STRIKE&gt;&lt;FONT color="#FF0000"&gt;resident [ReadingsTemp];&lt;/FONT&gt;&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;concatenate(&lt;SPAN&gt;&lt;FONT color="#FF0000"&gt;ReadingsTemp)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;load &lt;BR /&gt;MeterReference&lt;BR /&gt;,ReadingsID&lt;BR /&gt;,ReadingDateTime&lt;BR /&gt;,RptTime&lt;BR /&gt;,Value_Amount&lt;BR /&gt;resident [ENMATReadings]&lt;BR /&gt;where (MeterReference='$(vMet)');&lt;BR /&gt;next;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;left join(ReadingsTemp)&lt;BR /&gt;load * Resident MetRefTemp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;for it=0 to $(vNumRows)&lt;BR /&gt;let vAccName=peek('AccountName',$(it),'ClientList');&lt;/P&gt;
&lt;P&gt;[TempLoad]:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;load * &lt;BR /&gt;resident [ReadingsTemp]&lt;BR /&gt;where (AccNam='$(vAccName)');&lt;BR /&gt;store [TempLoad] into [lib://Admin - Data Loaders:DataFiles/metersdist_$(vAccName).qvd](qvd);&lt;BR /&gt;drop table [TempLoad];&lt;BR /&gt;next;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 04:55:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2003338#M83076</guid>
      <dc:creator>vinieme12</dc:creator>
      <dc:date>2022-11-11T04:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2003414#M83086</link>
      <description>&lt;P&gt;The loop should in your case be defined with:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF00FF"&gt;for it=0 to $(vNumRows)-1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;because the peek-index to access any rows starts by 0. For the cause with the duplicates look for the hints from &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/2751"&gt;@vinieme12&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;- Marcus&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 08:41:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2003414#M83086</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2022-11-11T08:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2003486#M83089</link>
      <description>&lt;P&gt;Thanks again - something so simple, yet easy to overlook!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know what is going on here?? Trying to store a file name with underscores instead of spaces for the customer name&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;let vFileAccName=lower(replace($(vAccName),' ','_'));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;store [TempLoad_$(vAccName)] into [lib://Admin - Data Loaders:DataFiles/metersdist_$(vFileAccName).qvd](qvd);&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV class="message error"&gt;
&lt;DIV class="selectable"&gt;&lt;FONT face="courier new,courier" size="2" color="#FF0000"&gt;The following error occurred:&lt;/FONT&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="message error"&gt;
&lt;DIV class="selectable"&gt;&lt;FONT face="courier new,courier" size="2" color="#FF0000"&gt;Unexpected token: 'UK', expected one of: ',', ')', ':', 'OPERATOR_PLUS', 'OPERATOR_MINUS', 'OPERATOR_MULTIPLICATION', 'OPERATOR_DIVISION', ...&lt;/FONT&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="message error"&gt;
&lt;DIV class="selectable"&gt;&lt;FONT face="courier new,courier" size="2" color="#FF0000"&gt;The error occurred here:&lt;/FONT&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="message error"&gt;
&lt;DIV class="selectable"&gt;&lt;FONT face="courier new,courier" size="2" color="#FF0000"&gt;let vFileAccName=lower(replace(A&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;UK&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; Limited,'','_'))&lt;/FONT&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-Ben&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 11:25:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2003486#M83089</guid>
      <dc:creator>BenjaminCoe1440</dc:creator>
      <dc:date>2022-11-11T11:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: For loop causing data to double</title>
      <link>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2003492#M83090</link>
      <description>&lt;P&gt;The variable-content is a string and therefore the call of the variable needs to be wrapped with single-quotes, like:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;let vFileAccName=lower(replace(&lt;STRONG&gt;'&lt;/STRONG&gt;$(vAccName)&lt;STRONG&gt;'&lt;/STRONG&gt; ,' ','_'));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 11:29:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/For-loop-causing-data-to-double/m-p/2003492#M83090</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2022-11-11T11:29:11Z</dc:date>
    </item>
  </channel>
</rss>

