Select to view content in your preferred language

Condition--Result Case statement syntax using Arcade

1299
5
Jump to solution
08-08-2023 05:34 PM
MPach
by
Frequent Contributor

I'm trying to essentially write an If...Then...Else statement using Arcade to change the text color in a Dashboard Indicator. I know what I need to do I just don't know the proper syntax for writing it and I'm having a problem finding a similar example. 

var color = ''   // using the var to change the color attribute

Decode($datapoint["capdep25"],     //attempting to using the "capdep25" column
  <=.25, {color = 'DF73FF'},      //if value is less than .25 make it pink 
  >.25 AND <=.50 , {color = '0070FF'}, //if value is between than make it blue
  >.50 AND <=.75, {color = '38A800'}, //if value is between than make it green
  >.75, {color = 'E60000'}, 0    //if value is greater than make it red
 );

I'm not sure if decode is the correct way to do this or there is a better way. 

Thanks for the help in advance!

 

0 Kudos
2 Solutions

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Decode() is a switch/case statement, it matches the values exactly. You want When() , which is a nested if/else.

Also, take a look at the logical operators.

var cd25 = $datapoint["capdep25"

var color = When(
    cd25 <= 0.25, "DE73FF",
    cd25 > 0.25 && cd25 <= 0.5, "0070FF",
    cd25 > 0.5 && cd25 <= 0.75, "38A800",
    "E60000"
)

 


Have a great day!
Johannes

View solution in original post

KenBuja
MVP Esteemed Contributor

You need to include the "#" in your color codes. And you can make your code a little simpler

var cd25 = $datapoint["capdep25"];

var color = When(
    cd25 > .001 && cd25 <= 0.25, "#DE73FF",   //pink
    cd25 <= 0.5, "#0070FF",                   //blue
    cd25 <= 0.75, "#38A800",                  //green
    "#E60000"                                 //red
);

View solution in original post

5 Replies
JohannesLindner
MVP Frequent Contributor

Decode() is a switch/case statement, it matches the values exactly. You want When() , which is a nested if/else.

Also, take a look at the logical operators.

var cd25 = $datapoint["capdep25"

var color = When(
    cd25 <= 0.25, "DE73FF",
    cd25 > 0.25 && cd25 <= 0.5, "0070FF",
    cd25 > 0.5 && cd25 <= 0.75, "38A800",
    "E60000"
)

 


Have a great day!
Johannes
MPach
by
Frequent Contributor

Thank you for the help and yeah, I definitely need to look at those operators I was trying to hack something together after work and was kind of out of patience at that point. I appreciate your help!

0 Kudos
MPach
by
Frequent Contributor

Ok, this time I'm at a loss. My indicator text is coming up black now for all values. I'm assuming it has to by that my statement logic is somehow incorrect, but it seems fine to me. 

 

var cd25 = $datapoint["capdep25"];

var color = When(
    cd25 > .001 && cd25 <= 0.25, "DE73FF",                 //pink
    cd25 > .25 && cd25 <= 0.5, "0070FF",                   //blue
    cd25 > 0.5 && cd25 <= 0.75, "38A800",                 //green
    "E60000"                                              //red
);

MPach_0-1691584667924.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

You need to include the "#" in your color codes. And you can make your code a little simpler

var cd25 = $datapoint["capdep25"];

var color = When(
    cd25 > .001 && cd25 <= 0.25, "#DE73FF",   //pink
    cd25 <= 0.5, "#0070FF",                   //blue
    cd25 <= 0.75, "#38A800",                  //green
    "#E60000"                                 //red
);
MPach
by
Frequent Contributor

Thank you @KenBuja . That's why my profile pic is the rolling eye emoji. It's usually something silly I'm missing.