Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Using variable in a dynamic way

Hello
Experts,

 

I’m having
a problem with variable.

 

I have lots of variable like Var10, Var20, Var30, ect… and I want to use these variable in a dynamic  way:

 

10, 20, 30, and so on is a filed value (fieldx) and I’d like to use the field value define variable name and to find variable value.

  If field  value is 10, I want to use $(Var10),

  If field value is 20, I want to use $(Var20),

 

Is it   possible?

I’ve tried  with $(=’Var’&fieldx), but    ’Var’&fieldx  is correct, while $(=’Var’&fieldx)  doesn’t  work.

 

Can anyone help me?

Thank you

10 Replies
Not applicable
Author

Have you tried creating a new variable that is 'Var'&fieldx and then referencing that variable instead?  That way you would be referencing $(newVariable) instead of $(=’Var’&fieldx). I haven't tried it, but it's just a suggestion off the top of my head.

jeffmartins
Partner - Creator II
Partner - Creator II

Hi cristina.pasqualucci,

You need to use same temporary variables to do this.

See the attached file. Hope this helps you.

Regards

Not applicable
Author

Hello cristina,

It will work this way:

=$(=('Var'&fieldx))

Thanks,

itsangad

advait_thakur
Creator III
Creator III

Hello Christina,

What you have tried is correct..$(=’Var’&fieldx)

will you please try using = prior to this.

Like =$(=’Var’&fieldx)

Thanks

Advait

Join the official Qlik Enthusiast's page here
https://www.linkedin.com/groups/6513382/
Not applicable
Author

Thank you all!

Unfortunately, these are not ok.

what do you think about using if statement?

if (fieldx = '10', &(Var10),

   if(fieldx = '20', &(Var20), ......))))

do you think  this will slow the document?

Many Thanks

cristina 

Not applicable
Author

Hello Cristina,

Do you need dynamic values at the script level or chart level.

Though =$(=('Var'&fieldx)) works fine at chart level.

Yes you can use the if statement as well. As per my understanding, it should not effect much.

thanks,

itsangad

Not applicable
Author

Hello,

I need it at chart level.

I try with if statement.

Thank you.

cristina

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try this, if your field values are exactly multiples of 10 (i.e., 10, 20, 30.......)

=Pick(FieldValue/10, $(Var10), $(Var20), $(Var30))

Hope this helps you.

Regards,

Jagan.

Not applicable
Author

Hello,

Can you upload your qvw.

thanks,

itsangad