Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
BenjaminCoe1440
Contributor III
Contributor III

for loop duplicates each iteration

 
 

I'm trying to 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.

 

Current effect is that the loop doubles the number of rows each iteration (e.g. 2400, 4800, 9600.. and so on...)

 

MetRefTemp table

AccNam AccountId MeterReference
Company A e4741f2f-#########-###### METER A
Company A e4741f2f-#########-###### METER B
... ... ...
Company B 4c3d8138-#########-###### METER ZZZZ

 

What ENMATReadings is pulling through is;

 

MeterReference ReadingsID ReadingDateTime RptTime Value_Amount (kWh)
METER A 0001A 10/10/2022 09:00 09:00 95461.05
METER B 0002A 10/10/2022 09:00 09:00 95462
... ... ... ... ...
METER ZZZZ B0001T 11/10/2022 09:30 09:30 94111

 

// 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;
Labels (4)
1 Solution

Accepted Solutions
rubenmarin

Hi, it will be better if you leave the concatente row uncommented, just comment the rows I posted.

Maybe ReadingTemp is autoconcatenating with the ENMATReadings, to avoid that add 'NoConcatenate' to the instruction that initially creates the table:

[ReadingsTemp]:
NoConcatenate LOAD * INLINE [

 

View solution in original post

3 Replies
rubenmarin

Hi, I think it's caused by

load *
resident [ReadingsTemp];

Just remove that rows before the concatenating, this is adding what is already in table, causing duplicates.

BenjaminCoe1440
Contributor III
Contributor III
Author

Nope, still doubling. Commented the following out, and the output (proof that it's doubling) is below 

BenjaminCoe1440_1-1668092849801.png

 

 

Output

BenjaminCoe1440_0-1668092681664.png

 

rubenmarin

Hi, it will be better if you leave the concatente row uncommented, just comment the rows I posted.

Maybe ReadingTemp is autoconcatenating with the ENMATReadings, to avoid that add 'NoConcatenate' to the instruction that initially creates the table:

[ReadingsTemp]:
NoConcatenate LOAD * INLINE [