Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Nighthawk
Contributor II
Contributor II

Variable inside variable

I have a variable called vUserChoices with definition below:

If(vUserChoice1 = 'A',

    If(vUserChoice2 = 'AA', $(vUserChooseAA),

    If(vUserChoice2 = 'AB', $(vUserChooseAB),

    If(vUserChoice2 = 'AC', $(vUserChooseAC)

)))

If(vUserChoice1 = 'B',

    If(vUserChoice2 = 'BA', $(vUserChooseBA),

    If(vUserChoice2 = 'BB', $(vUserChooseBB),

    If(vUserChoice2 = 'BC', $(vUserChooseBC)

)))

))

 

Later on, in my chart expression, I will use Count($(vUserChoices)), Sum($(vUserChoices)), etc. , so I suppose vUserChoices would be replaced by vUserChooseXX based on vUserChoice1 and vUserChoice2.

It seems the numbers I get is not what I expect. Is there anything wrong here with my syntax?

3 Replies
felipedl
Partner - Specialist III
Partner - Specialist III

Hi,

Ive seen the expression, seems to me like theres a syntax error on the middle, missing a comma here

"

)))

If(vUserChoice1 = 'B',

"

where it should be

"

))),

If(vUserChoice1 = 'B',

"

:

=

If(vUserChoice1 = 'A',

If(vUserChoice2 = 'AA',$(vUserChooseAA),
If(vUserChoice2 = 'AB',$(vUserChooseAB),
If(vUserChoice2 = 'AC',$(vUserChooseAC)
))),
If(vUserChoice1 = 'B',

If(vUserChoice2 = 'BA',$(vUserChooseBA),
If(vUserChoice2 = 'BB',$(vUserChooseBB),
If(vUserChoice2 = 'BC',$(vUserChooseBC)
))))
)

Ive idented the expression in the app since to me it becomes clearer as to the if / then / else of every statement.
Don't know the other things you need to do with the variables, but attached a quick example.


Hope it helps

Nighthawk
Contributor II
Contributor II
Author

Thanks for catching that missing comma. But still the numbers I get are slightly different than using the Count function directly in the chart expression like below. Is that even possible?

If(vUserChoice1 = 'A',

If(vUserChoice2 = 'AA',Count($(vUserChooseAA)),
If(vUserChoice2 = 'AB',Count($(vUserChooseAB)),
If(vUserChoice2 = 'AC',Count($(vUserChooseAC))
))),
If(vUserChoice1 = 'B',

If(vUserChoice2 = 'BA',Count($(vUserChooseBA)),
If(vUserChoice2 = 'BB',Count($(vUserChooseBB)),
If(vUserChoice2 = 'BC',Count($(vUserChooseBC))
))))
)

 

felipedl
Partner - Specialist III
Partner - Specialist III

I'd say its better if you explained what the end result should be (what data you have, whats the desired result and so on),  or share the app so we can take a look.