Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
adiarnon
Creator III
Creator III

set a variable

hi,
i want to set a variable in the script that have-
if($(v_metric_5)<90,'red',if($(v_metric_5)<95,'yellow',if($(v_metric_5)<=100,'green','gray')))

how can i do that?

i dont want that $(v_metric_5) will calculate

i want it to stay as a string

adi

4 Replies
Anil_Babu_Samineni

Not sure, what do you mean by string? May be this

if('$(v_metric_5)'<90,'red',if('$(v_metric_5)'<95,'yellow',if('$(v_metric_5)'<=100,'green','gray')))


How you have created this variable v_metric_5

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
vishalgoud
Creator III
Creator III

yes what is that v_metric_5 ??

is it is a variable ?? if varible then it will take the values as per the variable value.

if it is field  then you no need to consider it as string or any other format...

MindaugasBacius
Partner - Specialist III
Partner - Specialist III

adiarnon

Here is the difference between setting the variables:

SET vVariable = 1 + 2; //Value returned 1 + 2

LET vVariable = 1 + 2; //Value returned 3

See the attachment that might be helpful.

Screenshot_1.jpg

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Dollar Sign Expansion (DSE) always occurs in script, which is generally a blessing but sometimes a curse.  One workaround is to use a proxy character for the $ and then replace(). For example:

LET v1 = replace(

'if(@(v_metric_5)<90,''red'',if(@(v_metric_5)<95,''yellow'',if(@(v_metric_5)<=100,''green'',''gray'')))'

,'@','$');

You will need to double up your single quotes to allow them within the LET string.

Another approach is to use a proxy char for both $ and ' replacing both with a mapsubstring:

EscapeCharsMap:

MAPPING LOAD * INLINE [

from, to

@,$

|,'

];

LET v2 = MapSubString('EscapeCharsMap',

'if(@(v_metric_5)<90,|red|,if(@(v_metric_5)<95,|yellow|,if(@(v_metric_5)<=100,|green|,|gray|)))'

);

-Rob

http://masterssummit.com

http://qlikviewcookbook.com

http://www.easyqlik.com