Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Dynamic variables: Use Concatenated strings as variable in script

Hi,

I want to create a variable that contain different variables depending on selections i field

Background:

I have declared the following variables in the script:

let vProduct_1Max = 'Max({<Product = {'Product 1}>} Sales)';

let vProduct_2Max = 'Max({<Product = {'Product 1}>} Sales)';

let vProduct_3Max = 'Max({<Product = {'Product 1}>} Sales)';

I have created a table like this:

vProduct
vProduct_1
vProduct_2
vProduct_3

I want to create a variable in the script that concatenates the selected value in "vProduct" field with Max, to create:

$([Selected product]+"Max")

I have tried: LET vMax = ''&'$'&'(=' & chr(39) & '&vProduct&' & chr(39) & '&' & chr(39) & 'Max' & chr(39) &')';

This does not work however.

Any ideas?

5 Replies
Gysbert_Wassenaar

Create your table like this:

ProductMaxExpressions:

LOAD * INLINE [

Product, MaxSales

Product 1, Max({<Product = {'Product 1}>} Sales)

Product 2, Max({<Product = {'Product 2}>} Sales)

Product 3, Max({<Product = {'Product 3}>} Sales)

];

Then when you select a Product you can use =$(=only(MaxSales)) as expression in a chart or text box.


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks fot the reply.

However, my example represents a bigger solution where i vant more to crate and refer to more variables easily.

Thus, I want to use the technique to create more variables by ONLY relacing the "Max" string with for example: Min, Avg, Median, +++


Kushal_Chawda

if I understood correctly you can do something like below

Data:

LOAD Product,

    ID,

    Sale

FROM

[Rank.xlsx]

(ooxml, embedded labels, table is Sheet1);

Variable:

LOAD 1 as Temp

AutoGenerate(1);

for i=1 to FieldValueCount('Product')

let vProduct = FieldValue('Product','$(i)');

Concatenate(Variable)

LOAD '$(vProduct)' as PRODUCT,

      sum(Sale) as SelectedProduct,

      max(Sale) as MaxSale

Resident Data

where Product = '$(vProduct)'

Group by Product;

NEXT i

DROP Field Temp;

Untitled.jpg

MarcoWedel

Hi,

maybe you could use one parameterized variable instead, maybe similar to this:

Re: Variable troubles

hope this helps

regards

Marco

Not applicable
Author

Hi,

I am a new user of qlikview. the scrip below does axactly what i would like to do.with my data. i tried it with my data but it is not working. i can't understant why:

Data:

LOAD Opération_N° as Product,

     Qté,

     Mnt_Net_client as Sale,

     TF

   //  Qté*Mnt_Net_client as [MntM] ,

  //   Qté*TF as [TFM] 

FROM

(biff, embedded labels, table is Feuil2$);

Variable:

LOAD 1 as Temp

AutoGenerate(1);

for i=1 to FieldValueCount('Product')

let vProduct = FieldValue('Product','$(i)');

Concatenate(Variable)

LOAD '$(vProduct)' as PRODUCT,

      sum(Sale) as SelectedProduct,

      max(Sale) as MaxSale

Resident Data

where Product = '$(vProduct)'

Group by Product;

NEXT i

DROP Field Temp;

I Capturesaleop.PNGCapture_opperation.PNG