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: 
Not applicable

Get a variable by its name

Good day,

I would like to call a variable, but I would like to specify its name dynamically.

Let's say I have a dimension "test" and 3 variables : "varAAA", "varBBB", and "varCCC".

Nowaday, I use the following syntax :


if(test = 'AAA', $(varAAA),
if(test = 'BBB', $(varBBB),
if(test = 'CCC', $(varCCC),
)))


If my variable were dimensions, I'ld use :


[var$(test)]


If variable could be arrays, I'ld use :


$(var[test])


If a function "getVariableByName" would exisits, I'ld use :


$(=getVariableByName('var' & test))


Is there another solution ?

2 Replies
boorgura
Specialist
Specialist

you can use this logic i believe:

=$(='v'&Test)

where Test is you field with values "AAA, BBB, CCC"

and vAAA, vBBB, vCCC are your variables.

if you should vary by selection:

it might be something like this:

='$(v$(=getFieldSelections(Test)))'

(Limitation would be works for one selection only)

Not applicable
Author

Hi Rocky,

This doesn't work.

Here is a sample application (see attached file).

I would like to make an array that displays :


ABOVE : 21000
BELOW : 210
EQUAL : 2100

To filter my data, I have 2*3 variables :


// Set Analysis filters
LET var_sa_ABOVE = '>$' & '(=DimDate)';
LET var_sa_BELOW = '<$' & '(=DimDate)';
LET var_sa_EQUAL = '$' & '(=DimDate)';

// If filters
LET var_if_ABOVE = 'Date > ' & 'DimDate';
LET var_if_BELOW = 'Date < ' & 'DimDate';
LET var_if_EQUAL = 'Date = ' & 'DimDate';


Nowaday, I use the following formula :


if(DimChoice = 'ABOVE',
sum({$ <Date={'$(=var_sa_ABOVE)'}>} Value),
if(DimChoice = 'BELOW',
sum({$ <Date={'$(=var_sa_BELOW)'}>} Value),
if(DimChoice = 'EQUAL',
sum({$ <Date={'$(=var_sa_EQUAL)'}>} Value),
)))


or


if(DimChoice = 'ABOVE',
sum(if ( $(var_if_ABOVE), Value)),
if(DimChoice = 'BELOW',
sum(if ( $(var_if_BELOW), Value)),
if(DimChoice = 'EQUAL',
sum(if ( $(var_if_EQUAL), Value)),
)))


I would like to use a formula in a single line, something like :


sum(if ( $(var_if_$(DimChoice)), Value))