Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

hcavanhoogdalem
New Contributor III

Using field content as variable name

Hi,

I have a problem with using the content of a field as a variable name that needs to be expanded.

Consider this situation:

In the script i set these (i want the users to be able to play with these values)

LET vNiveau1Factor = 10;

LET vNiveau2Factor = 20;

LET vNiveau3Factor = 30;

LET vNiveau4Factor = 40;

INLINE table:

NiveauFactor
Niveau 1vNiveau1Factor
Niveau 2vNiveau2Factor
Niveau 3vNiveau3Factor
Niveau 4vNiveau4Factor

CHART

Dimension (Niveau)Expression 1: =FactorExpression2: ?????
Niveau 1vNiveau1FactorI would like to have an expression here that shows 10 (or current value)
Niveau 2vNiveau2FactorI would like to have an expression here that shows 20 (or current value)
Niveau 3vNiveau3FactorI would like to have an expression here that shows 30 (or current value)
Niveau 4vNiveau4FactorI would like to have an expression here that shows 40 (or current value)

I would like Expression2 to show the actual value of the variables.

I can't seem to find the correct $-expansion for this case.

=$('=Factor') doesn't work....

Could any1 shine a light on this?

Thanks

Herbert

6 Replies
sdmech81
Valued Contributor

Re: Using field content as variable name

Hi,

in inline table add one more colum say Value then pass those

vNiveau1Factor

vNiveau2Factor

vNiveau3Factor

vNiveau4Factor

Declare variables in front end..

sdmech81
Valued Contributor

Re: Using field content as variable name

please check rough example fr how to pass variable to inline load

Thanks

Re: Using field content as variable name

//Script

LET vNiveau1Factor = 10;

LET vNiveau2Factor = 20;

LET vNiveau3Factor = 30;

LET vNiveau4Factor = 40;

Data:

Load

  Niveau,

  Factor

Inline

[

  Niveau, Factor

  Niveau 1, vNiveau1Factor

  Niveau 2, vNiveau2Factor

  Niveau 3, vNiveau3Factor

  Niveau 4, vNiveau4Factor

];

Create a table

Dimension

Niveau

Expression

1)

Factor

2)

Pick(

  Match(Niveau,'Niveau 1','Niveau 2','Niveau 3','Niveau 4'),

  '$(vNiveau1Factor)','$(vNiveau2Factor)','$(vNiveau3Factor)','$(vNiveau4Factor)'

)

Re: Using field content as variable name

Manish solution works, But bit long as per my experience if we have 30 Variables then we may need to create Long Expression.

May be another solution with Inline Memory

LET vNiveau1Factor = 10;

LET vNiveau2Factor = 20;

LET vNiveau3Factor = 30;

LET vNiveau4Factor = 40;

Data:

Load * Inline

[

  Niveau, Factor, Factor1

  Niveau 1, vNiveau1Factor, "$(vNiveau1Factor)"

  Niveau 2, vNiveau2Factor, "$(vNiveau2Factor)"

  Niveau 3, vNiveau3Factor, "$(vNiveau3Factor)"

  Niveau 4, vNiveau4Factor, "$(vNiveau4Factor)"

];

Create Straight Table

Dimension -- Niveau, Factor

Expressions are

1) Sum(Factor1)

Capture.PNG

hcavanhoogdalem
New Contributor III

Re: Using field content as variable name

This works up to a point, if I use an inputbox to change the value of the variable, somehow the "$(vNiveauXFactor)" does not change with it.

I got it to work using the pick-function.

Which isn't really what I was looking for, but it works and is straightforward.

Thanks for all your answers.

Re: Using field content as variable name

Hi,

if being able to change the value during runtime is the reason for using variables in the first place, then you might as well consider using Inputfields instead.

hope this helps

regards

Marco

Community Browser