Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

For Loop last Value in Variable Lost

Hello Community,

i have a strange phenomenon. I have in a SharePoint List our Plants which will be connected over the next month to SAP. Therefore i have this following table out of the SharePoint List:

Support_1.JPG

Now the following QV Code (as a picture and as Text) to test the single line output from my for loop:

Support_2.JPG

Dim_Plants_SAP:

LOAD

     Plant_Number,

     SAP_Company_Code,

     num(SAP_seit) as SAP_Datum

FROM

(qvd) where len(SAP_seit)>=1;

LET NumRowsFilter=NoOfRows('Dim_Plants_SAP');

trace $(NumRowsFilter);

FOR x=1 to $(NumRowsFilter)

trace $(x);

//Bei jedem Schleifendurchlauf werden die Felder "Plant_Number, SAP_Comapny_Code, SAP_Datum" geholt und in eine Variable gespeichert für die spätere Filterung der FACT_SAP_AHC_FI_BOOKINGS.qvd

Let vD_Plant_Number=FieldValue('Plant_Number',$(x));

Let vD_SAP_Company_Code=FieldValue('SAP_Company_Code',$(x));

Let vD_SAP_Datum=FieldValue('SAP_Datum',$(x));

//Ausgabe der Variablen im Skript Fenster zur Prüfung

trace $(vD_Plant_Number);

trace $(vD_SAP_Company_Code);

trace $(vD_SAP_Datum);

trace $(x);

next

When i execute this you will see under the Debug Mode that i lost the "SAP_Datum" from the last line:

Support_3.JPG

For the the other two lines i will get my "SAP_Datum" with 43221 ande 43160, but for the Plant 37 i lost the "SAP_Datum". But it is in the table you see on the Top and i have no ideas, why the for loop cant resolve me the "SAP_Datum".

I read in the help of QlikView that FieldValue only take distinct Values so for the two lines, they have the same Date, so that the last Date will take from Plant 37 to 24. Which function will work without distinct values?

Have anyone an idea for me, what i do wrong?

Kind Regards

D.P.

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

I found the solution. If someone is interesting in this here it comes:

Instead of the FieldValue() function i used the Peek function. But attention, the Peek() function start the Count with 0 instead of 1 like the FieldValue() function. Here the hole Code snip which will work:

Dim_Plants_SAP:

LOAD

     Plant_Number,

     SAP_Company_Code,

     num(SAP_seit) as SAP_Datum

FROM

(qvd) where len(SAP_seit)>=1;

LET NumRowsFilter=NoOfRows('Dim_Plants_SAP')-1;

trace $(NumRowsFilter);

FOR x=0 to $(NumRowsFilter)

trace $(x);

//Bei jedem Schleifendurchlauf werden die Felder "Plant_Number, SAP_Comapny_Code, SAP_Datum" geholt und in eine Variable gespeichert für die spätere Filterung der FACT_SAP_AHC_FI_BOOKINGS.qvd

Let vD_Plant_Number=Peek('Plant_Number',$(x),'Dim_Plants_SAP');

Let vD_SAP_Company_Code=Peek('SAP_Company_Code',$(x),'Dim_Plants_SAP');

Let vD_SAP_Datum=Peek('SAP_Datum',$(x),'Dim_Plants_SAP');

//Ausgabe der Variablen im Skript Fenster zur Prüfung

trace $(vD_Plant_Number);

trace $(vD_SAP_Company_Code);

trace $(vD_SAP_Datum);

trace $(x);

next;

All lines with bold are changed.

View solution in original post

1 Reply
Anonymous
Not applicable
Author

I found the solution. If someone is interesting in this here it comes:

Instead of the FieldValue() function i used the Peek function. But attention, the Peek() function start the Count with 0 instead of 1 like the FieldValue() function. Here the hole Code snip which will work:

Dim_Plants_SAP:

LOAD

     Plant_Number,

     SAP_Company_Code,

     num(SAP_seit) as SAP_Datum

FROM

(qvd) where len(SAP_seit)>=1;

LET NumRowsFilter=NoOfRows('Dim_Plants_SAP')-1;

trace $(NumRowsFilter);

FOR x=0 to $(NumRowsFilter)

trace $(x);

//Bei jedem Schleifendurchlauf werden die Felder "Plant_Number, SAP_Comapny_Code, SAP_Datum" geholt und in eine Variable gespeichert für die spätere Filterung der FACT_SAP_AHC_FI_BOOKINGS.qvd

Let vD_Plant_Number=Peek('Plant_Number',$(x),'Dim_Plants_SAP');

Let vD_SAP_Company_Code=Peek('SAP_Company_Code',$(x),'Dim_Plants_SAP');

Let vD_SAP_Datum=Peek('SAP_Datum',$(x),'Dim_Plants_SAP');

//Ausgabe der Variablen im Skript Fenster zur Prüfung

trace $(vD_Plant_Number);

trace $(vD_SAP_Company_Code);

trace $(vD_SAP_Datum);

trace $(x);

next;

All lines with bold are changed.