Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
marcel_olmo
Partner Ambassador
Partner Ambassador

For Loop Question (I want to loop over all the fields of a table without knowing their names)

Hey guys, I have a table with 40 fields. And I want to check if they are numbers or strings.

If they were 5 o 6 fields, I'll do it manually as always, loading all the fields and check if they are numbers or strings with isNum() and isText().

But how about if I have 40 fields? How can I do it dynamically?

I was thinking about doing a loop over the fields (with a for...next) but my problem is that there is fieldValue() function, but not a fieldName() function (as far as I know).

Any help would be appreciated.

3 Replies
Not applicable

There is a FieldName() function. It is FieldName(#, 'TableName').

You may be able to do:

For i = 0 to 39 ' Does it start at 0 or 1?
IsNum(FieldName(i,'TableName')...
Next i


I didn't really test that out, but maybe it can give you a start.

marcel_olmo
Partner Ambassador
Partner Ambassador
Author

Thanks NMiller for your useful help.

My problem is that, if I do what you wrote in your last post, I have to put into the (FOR...NEXT) loop a LOAD RESIDENT STATEMENT of my desired table, and I get N tables with N Fields.

I've found no way to do the loop inside the loaded table. 😞

I mean :

What usually works :

for I = 0 to I = 100

load var1,....varN

resident Table1

next

What it needs to work in my case :

load

for I = 0 to I = 100

//stuff with my fields

next

resident Table1

Not applicable

Could you do something like:

LOAD Key, FieldName(0, 'Table');
For i = 1 to 39
INNER JOIN LOAD Key, FieldName(i, 'Table')
FROM Table;
Next i


That should essentially give you a copy of the table, although in a rather roundabout way.

What manipulations are you doing using IsNum()? Maybe there is another way to handle it on a Resident table?