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: 
yvesqlik
Partner - Contributor III
Partner - Contributor III

Use variable dynamically as function

I have a set of variable

var1= $1+1;

var2=$1+2;

var3=$1+3;

my table

A

Var_Index

Value

X

1

10

Y

2

100

Z

3

1000

I like to create a NewColumn that depends from the columns ‘Var_Index’ and ‘Value’

For example, the first line Var_Index=1, Value=10 then NewColumn=$(var1(10))=10+1=11

A

Var_Index

Value

NewColumn

X

1

10

11

Y

2

100

102

Z

3

1000

1003

Load

            A,

            Value,

            $(var&Var_Index(Value)) as NewColumn

Resident Table;

My code doesn’t work, how can I modify it that it works.

I try to avoid pick(Var_Index,…) and  If(Var_Index=….) because my list of variable is longer than this sample and I create the variable dynamically.

Thanks for your help and answer.

Nice Week End!

Labels (1)
5 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

SET var1= $1+1;

SET var2= $1+2;

SET var3= $1+3;

Data:

LOAD *, pick(Var_Index, $(var1(Value)), $(var2(Value)), $(var3(Value))) as NewColumn INLINE [

    A, Var_Index, Value

    X, 1, 10

    Y, 2, 100

    Z, 3, 1000

];


talk is cheap, supply exceeds demand
yvesqlik
Partner - Contributor III
Partner - Contributor III
Author

pick(Var_Index, $(var1(Value)), $(var2(Value)), $(var3(Value)))

this solution is not good because the variable will be create automatically

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Then create the pick expression automatically too.


talk is cheap, supply exceeds demand
marcus_sommer

Could you give a more descriptive example and why you need for this variables - maybe another approaches are more suitable, maybe: rangesum(Var_Index, Value) as NewColumn.

- Marcus

yvesqlik
Partner - Contributor III
Partner - Contributor III
Author

It was tricky but i get it...

Thanks!