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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to pass field names of table into variable

hi,

I am trying below script to pass field name into variables.

DataToReduce:

LOAD Item AS Item1,

     Status AS Status1,

     Store As Store1

FROM

Item.xlsx

(ooxml, embedded labels, table is DataToReduce);

let VNo.ofFields = NoOfFields('DataToReduce'); //To find No.of Fields in the table

for i=1to $(VNo.ofFields)  //

let VFieldName=FieldName($(i),'DataToReduce'); //To find FieldName in the ith position.

FieldNames:

LOAD $(VFieldName) AutoGenerate 1;

next i;

output should be VFieldName=Item1,Status1,Store1.

But getting error like item1 field not found.

Can any one help on this issue.

Thanks in advance

1 Solution

Accepted Solutions
swuehl
MVP
MVP

That's because your dollar sign expansion will expand to something like

LOAD Item1, Status1, Store1

autogenerate 1;

But your data source (i,e, autogenerate 1) does not show these fields, and you are not aliasing them from an (e,g, constant) expression.

View solution in original post

7 Replies
swuehl
MVP
MVP

That's because your dollar sign expansion will expand to something like

LOAD Item1, Status1, Store1

autogenerate 1;

But your data source (i,e, autogenerate 1) does not show these fields, and you are not aliasing them from an (e,g, constant) expression.

Not applicable
Author

can you explain that..

swuehl
MVP
MVP

Do you expect to get

LOAD Item1, Status1, Store1

autogenerate 1;

when the variable expand or something else?

And if so, what do you expect to be the result of that LOAD statement? How should the resulting table look like?

Not applicable
Author

Do you have any idea to store all field names into a variable.

Ex: var1=item1,Status1,Store1.

swuehl
MVP
MVP

let VNo.ofFields = NoOfFields('DataToReduce'); //To find No.of Fields in the table

for i=1to $(VNo.ofFields)  //

let VFieldName=FieldName($(i),'DataToReduce'); //To find FieldName in the ith position.

FieldNames:

LOAD $(i) as ID, '$(VFieldName)' as Field

AutoGenerate 1;

next i;

Fields:

LOAD CONCAT(Field,', ', ID) as Fields

RESIDENT FieldNames;

Let vFieldNames = Peek('Fields', 0,'Fields');

DROP TABLES Fields, FieldNames;

Not applicable
Author

thankyou..so much its works..

Fr1
Contributor
Contributor

Hi, I am having an error : Field '1' not found

What could be the solution for this ?