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

a dynamic variable

hello everybody 🙂

i would generate a generic variable. is it possible to name the variable in step of a for next statement by the step?

VG

23 Replies
marcus_sommer

For me with QV 11.2 it worked. With another release the handling of fieldname() and/or with the quotes might have slightly changed and the workaround with evaluate() might be now unnecessary - are you sure that you took my code-snippet 1:1? If not there might be a small syntax-issue.

- Marcus

FrankTheTank
Contributor III
Contributor III
Author

yes, I only changed the source. But I use Qlik Sense. does it matter?

marcus_sommer

The general workings should be the same but the release (of the engine) is surely different. I don't know if it's in your case worth to search for the cause - maybe it's just the legacy-mode or something similar - but I'm sure that these logic could be applied.

- Marcus

FrankTheTank
Contributor III
Contributor III
Author

i have testet your script without the evaluate function.

the same Problem.

t1:
first 1 LOAD * FROM [lib://OjO/OJO.XLSX](ooxml, embedded labels, table is OJO);


t2:
load peek('F') & '[' &
    	fieldname(' & recno() & ', 't1')
        & ']' & 
    if(recno() < nooffields('t1'), '&"|"&') as F
autogenerate nooffields('t1');

to see what is in 'F'.

image.png

marcus_sommer

For me it  worked:

FieldnameWithEvaluate.JPG

Before going further just check if the normal fieldname() function itself worked, with:

fieldname(1, 't1')

if yes, try it with:

fieldname(recno(), 't1') and then with:

fieldname(evaluate(recno()), 't1') or fieldname(eavluate('recno()'), 't1')

and if this don't worked with:

evaluate('fieldname(' & recno() & ', ''t1'')')

whereby the exact use of the quotes is important. An alternatively to the last could be:

evaluate('fieldname(' & recno() & ',' & chr(39) & 't1' & chr(39) & ')')

- Marcus

 

FrankTheTank
Contributor III
Contributor III
Author

fieldname(1, 't1') => works

fieldname(recno(), 't1') => works

fieldname(evaluate(recno()), 't1') => works

fieldname(evaluate('recno()'), 't1') => everything is NULL

evaluate('fieldname(' & recno() & ', ''t1'')') => every entry is "F"

evaluate('fieldname(' & recno() & ',' & chr(39) & 't1' & chr(39) & ')') => works

if I take the last way in your script in further steps i get an error. 

image.pngimage.png

 

marcus_sommer

This is the desired approach:

fieldname(recno(), 't1')

and everything else with the evaluate-stuff was just a workaround for a seemingly strange bug/feature in 11.2.

- Marcus

FrankTheTank
Contributor III
Contributor III
Author

OK. But if I continue to use that is the error shown by me. what do I do about it?

 

 

But thank you in advance

 

marcus_sommer

Which error - the above one from the screenshot? If yes it meant that the record-check within field-concat - recno() vs. nooffields() - didn't work properly. Why I don't know - but could it be that Qlik tries to load a column with a blank fieldname (this happens if there is any content within any record of this column).

- Marcus

FrankTheTank
Contributor III
Contributor III
Author

Yes, exactly this mistake. And yes, there is content in the columns. For each column, the program also does, for more than one column bicht. Is this due to a faulty understanding?