Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
!Hi all,
Currently I have this expression:
sum({$<Age={'$(vAgeRange)'}>} Amount)
I have 2 buttons in my layout with an action that will change the value of the vAgeRange variable.
Now, I need to store this expression in a variable in the script so that I can call the variable in my chart instead of using the expression in chart.
SET vExp_Amount = sum({$<Age={'$(vAgeRange)'}>} Amount);
The problem is that the vAgeRange will be evaluated in the script level. Due to this, the expression become static in the chart (since the vAgeRange is not evaluated anymore in the chart)
Any idea on how I can get around this?
*Attached is the example with the 2 workarounds suggested below. Thanks for the help!
The $ expansion in the set statement IS evaluated (even though this a SET):
SET vExp_Amount = sum({$<Age={'$(vAgeRange)'}>} Amount);
As $(vAgeRange) may expand to <empty string> at this stage in the script execution, so the actual statement will become:
SET vExp_Amount = sum({$<Age={''}>} Amount);
Which is not what you want. To get around this, defer the evaluation like this:
Set vExp_Amount = sum({$<Age={'#(vAgeRange)'}>} Amount);
Let vExp_Amount = Replace(vExp_Amount, '#', '$');
Does that answer your question?
Try in text object like $(vAgeRange)
The $ expansion in the set statement IS evaluated (even though this a SET):
SET vExp_Amount = sum({$<Age={'$(vAgeRange)'}>} Amount);
As $(vAgeRange) may expand to <empty string> at this stage in the script execution, so the actual statement will become:
SET vExp_Amount = sum({$<Age={''}>} Amount);
Which is not what you want. To get around this, defer the evaluation like this:
Set vExp_Amount = sum({$<Age={'#(vAgeRange)'}>} Amount);
Let vExp_Amount = Replace(vExp_Amount, '#', '$');
Does that answer your question?
Here is another option suggested by Stefan here:
Expression as a variable with $-sign expansion
LET vExp_Amount = 'Sum({$<Age={"$' & '(vAgeRange)"}>} Amount)';
Thank you Jonathan and Sunny! Both methods works, but I've chosen Jonathan's method as it is easier to read. I've edited my first post with an example containing both method. Hope this will help others.