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: 
priyarane
Specialist
Specialist

Replace variable

Hi Community,

I have variable For Ex:

vTest

Value for the above variable is sum({<Cntry = {'IN'}>}Sales) + sum({<Cat= {'ABC'}>}Amt)

Now I need to use that variable in some other place like

sum({<Cntry = {'IN'},Prd {1}>}Sales) + sum({<Cat= {'ABC'},Prd {1}>}Amt), so here I am adding one more with ""Prd {1}""

But I have to use only like $(vTest) and need to incude ""Prd {1}""

How can we use like above, IF condition should not be used

-Priya

1 Solution

Accepted Solutions
marcus_sommer

You could use a variable with parameter like this one:

vTest

sum({<Cntry = {'IN'}, Prd = {$1} >}Sales) + sum({<Cat= {'ABC'}>}Amt)

and then you could use the variable as expression like:

=$(vTest(1))

or

=$(vTest('*'))

- Marcus

View solution in original post

4 Replies
adamdavi3s
Master
Master

Can you explain the scenario?

e.g. do you need the different variables on different sheets?

You could always add a variable called say v_Prd and set this to 1 or '*' by using some trigger that works in your particular scenario

marcus_sommer

You could use a variable with parameter like this one:

vTest

sum({<Cntry = {'IN'}, Prd = {$1} >}Sales) + sum({<Cat= {'ABC'}>}Amt)

and then you could use the variable as expression like:

=$(vTest(1))

or

=$(vTest('*'))

- Marcus

trdandamudi
Master II
Master II

Give a try on the below:

Declare variable vTest as below:

if($1=1,

     sum({<Cntry = {'IN'}>} Sales) + sum({<Cat= {'ABC'}>} Amt)

,

     sum({<Cntry = {'IN'},Prd ={'1'}>} Sales) + sum({<Cat= {'ABC'},Prd ={'1'}>} Amt)

)

Now you can use the above in a expression like below:

Expression:

$(vTest(1))

If you want to use the second expression in the vTest then as below:

$(vTest(2))

Hope this helps....

rubenmarin

The option given by Adam is a good otion.

There is also the possibility to use a parametrized variable like:

sum({<Cntry = {'IN'}, $1>}Sales) + sum({<Cat= {'ABC'}, $1>}Amt)

And call the variable like:

=$(vTest(Prd={1}))

Not tested by I did something similar and the $1 doesn't gives an error when the variable is called just with "=$(vTest)", in case Prd has some null values and you don't want to exclude them.