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

Using variables in a For... Loop

I am trying to load data from several data sources that is in identical format in each source. Each time I load the data I need to tag it with the product type. The file name to load from and the product type to tag the data with are stored as a variables. I want to be able to loop through my load code for the various variable names.

So for each of the multiple product types I want to load the following code, using variables varProduct1, varFile1, varProduct2, varFile2, varProduct3...

TableX:

Add LOAD

     $(varProduct1) as Product,

     *

FROM

[$(varFile1)]

(biff, embedded labels, header is 1 lines, table is ProdData$);

Something like -

For a = 1 to 9

     TableX:

     Add LOAD

          $('varProduct'&$(a)) as Product,

          *

     FROM

     [$('varFile'&$(a))]

     (biff, embedded labels, header is 1 lines, table is ProdData$);

Next a

However QlikView doesn't like $('varProduct'&$(a)) or $('varFile'&$(a)). Is it possible to string together text and a variable value and get QlikView to recognise it as a variable?

1 Solution

Accepted Solutions
CELAMBARASAN
Partner - Champion
Partner - Champion

hi,

     use it like this.

    

For a = 1 to 9

     TableX:

     Add LOAD

          'varProduct'&$(a) as Product,

          *

     FROM

     ['varFile'&$(a)]

     (biff, embedded labels, header is 1 lines, table is ProdData$);

Next a

No need to use strings within dollar expansions.

Celambarasan

View solution in original post

2 Replies
CELAMBARASAN
Partner - Champion
Partner - Champion

hi,

     use it like this.

    

For a = 1 to 9

     TableX:

     Add LOAD

          'varProduct'&$(a) as Product,

          *

     FROM

     ['varFile'&$(a)]

     (biff, embedded labels, header is 1 lines, table is ProdData$);

Next a

No need to use strings within dollar expansions.

Celambarasan

Not applicable
Author

Thank you!

I also managed to use this (without ampersand):

For a = 1 to 9

     TableX:

     Add LOAD

          '$(varProduct$(a))' as Product,

          *

     FROM

     [$(varFile$(a))]

     (biff, embedded labels, header is 1 lines, table is ProdData$);

Next a