Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
rtr13
Contributor III
Contributor III

if condition with range of values

Hi All,

I am trying to set certain colors to values and am having troubles with my if statement. Currently, this is what I have as my if statement to determine colors:

=if(change_percent >= 0 ,green(),
     if(change_percent > (-5),rgb(255,0,0),
         if(change_percent > 0 and change_percent <= -5,rgb(255,205,3))))

Currently, the range of values in this case between 0 and -5, isn't calculating properly. Does anyone know what I am doing wrong?

Thanks,

Rose

Labels (2)
6 Replies
dplr-rn
Partner - Master III
Partner - Master III

=if(change_percent >= 0 ,green(),
if(change_percent > (-5),rgb(255,0,0), did you mean change_percent < -5? because > -5 would mean between -5 and 0
if(change_percent > 0 and change_percent <= -5,rgb(255,205,3))))  assuming this is part you want between -5 and 0. it should be change_percent < 0 and change_percent >= -5

rtr13
Contributor III
Contributor III
Author

Unfortunately that didn't work... I am looking for values above 0 to be green, between negative 5 and 0 to be yellow and anything lower than -5 should be red. 

Thanks!

Rose

dplr-rn
Partner - Master III
Partner - Master III

did you try like below?

=if(change_percent >= 0 ,green(),
if(change_percent < (-5),rgb(255,0,0), 
if(change_percent < 0 and change_percent >= -5,rgb(255,205,3))))

Brett_Bleess
Former Employee
Former Employee

Rose, attaching a sample app on this one will be the best way to get a working solution, this way folks can dig into things to try to figure out why the expression is not working, which would likely have to do with the data model etc.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
rtr13
Contributor III
Contributor III
Author

Hello,

Thank you for your responses! I attached a screenshot of how my data is formatted in the data model. In addition, below is the expression I put into my text color section of the expressions. 

=if(percentchange >= 0 ,green(),
     if(change_percent > -5,rgb(255,0,0),
          if(percentchange < 0 and percentchange >= -5,rgb(255,205,3))))

I also included a screenshot of the values in my table. I formatted the pivot table to have the columns as rows (just as an FYI)! I also formatted the values into percentages in my table, could this be a reason why the expression won't work? 

Sorry for the delay in responses, I appreciate the help!

 
 
ManimekalaiS
Partner - Contributor
Partner - Contributor

=if(change_percent >= 0 ,green(),
if(change_percent < 0 and change_percent >= -5,yellow(),
if(change_percent < 0 and change_percent < -5,red()))) // Here ii) <0 and >-= -5 falls (-1,-2,-3,-4). iii) <0 and <-5 falls(-6,-7,-8....)