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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Using a Variable as a a Field in a Table

Hi,

I would like to use a variable as a field in one of the tables.

How can I do that.

Thanks & Regards

4 Replies
biester
Specialist
Specialist

e.g.:

let var = 5353;

load $(var) as Value ......

Rgds,
Joachim

Not applicable
Author

Actually I am using the following For statement Statement

FOR EACH file in filelist('C:\Documents and Settings\*.csv*')

Now when I am loading data from each of the files from the given folder I also want the filename as on of the fields but this attempt is giving me some error.

Please note :

FOR EACH file in filelist('C:\Documents and Settings\*.csv*')

TEMP:

LOAD

Field1,

Field2

FROM

[$(file)]

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);



but the following code does not work:

FOR EACH file in filelist('C:\Documents and Settings\*.csv*')

TEMP:

LOAD

Field1,

Field2,

$(file) as filename

FROM

[$(file)]

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);



Not applicable
Author

Hi,

I am trying to use a variable as a Field.

Here is exactly what I am exactly trying to do:

FOR EACH file in filelist('C:\Documents and Settings\*.csv*') // reads all CSV files in the given folder

TEMP:

LOAD

Field1,

Field2

FROM

[$(file)]

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

NEXT

The above code works fine.

but I also want the the filename as one of the fields and hence I am trying the following code which throws some error.

FOR EACH file in filelist('C:\Documents and Settings\*.csv*')

TEMP:

LOAD

Field1,

Field2,

$(file) as filename

FROM

[$(file)]

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

NEXT

Please let me know that where I am going wrong and how can I meet my objective of having the file name as one of the fields.

Thanks & Regards,

Rohit



biester
Specialist
Specialist

Try

'$(file)' as filename