Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
mhorsfall
Contributor II
Contributor II

If Statement using Variables for Colors

I have an if statement: 

IF($(vForecastVarianceMTD) < 0,
rgb(255, 0, 0),
rgb(0, 153, 0))

The goal here is to make red if negative, and green if >= 0. I am currently getting the error: Error in expression: ')' expected. Not sure where the ')' is expected, but when I look at the sample script below, it outputs the full expression for the variable but it does not show the < 0, prior to showing the rgb part. When I put just the variable in a KPI it shows the value that I expect it to show. Any thoughts from the community? 

Labels (1)
1 Solution

Accepted Solutions
anat
Master
Master

seems your logic looks good,

can you try by placing the actual expression in if statement.

IF(sum(sales) < 0,rgb(255, 0, 0),rgb(0, 153, 0))

View solution in original post

5 Replies
Lisa_P
Employee
Employee

What is inside your vForecastVarianceMTD variable and where are you trying to apply this ?

anat
Master
Master

seems your logic looks good,

can you try by placing the actual expression in if statement.

IF(sum(sales) < 0,rgb(255, 0, 0),rgb(0, 153, 0))

ajaykakkar93
Specialist III
Specialist III

Hi,
Please check the value of $(DynamicTableName), what is the output ,
below is also another way to add color using #

IF($(DynamicTableName) < 0,
'#ff0000',
'#009900'
)

Please mark the correct replies as Solution. Regards, ARK
Profile| GitHub|YouTube|Extension|Mashup|Qlik API|Qlik NPrinting

mhorsfall
Contributor II
Contributor II
Author

There was an extra parenthesis in the statement for the variable -- when I put that expression on its own there was no issue because nothing else was coming after, which is why it allowed an output I presume, but then when put in variable form it could not interact with the rest of the expression because of that extra parentheses. Was able to resolve this by putting the entire expression in the if statement and troubleshooting that way. 

mhorsfall
Contributor II
Contributor II
Author

There was an extra parenthesis in the statement for the variable -- when I put that expression on its own there was no issue because nothing else was coming after, which is why it allowed an output I presume, but then when put in variable form it could not interact with the rest of the expression because of that extra parentheses. Was able to resolve this by putting the entire expression in the if statement and troubleshooting that way.