Select to view content in your preferred language

Replace values with text using Arcade in a list

1662
10
Jump to solution
08-18-2023 11:40 AM
dwold
by
Frequent Contributor

How would I convert values (0,1) with yes/no in a list?

This is what I tried but not right

dwold_0-1692383872574.pngdwold_2-1692383948626.png

Data Table:

dwold_1-1692383902087.png

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You should use the When function. Is the field numeric or a string?

//if it's a number
var over = When($datapoint['IsOverriden'] == 0, 'No',
                $datapoint['IsOverriden'] == 1, 'Yes',
                '');
//if it's a string
var over = When($datapoint['IsOverriden'] == '0', 'No',
                $datapoint['IsOverriden'] == '1', 'Yes',
                '');

View solution in original post

10 Replies
KenBuja
MVP Esteemed Contributor

You should use the When function. Is the field numeric or a string?

//if it's a number
var over = When($datapoint['IsOverriden'] == 0, 'No',
                $datapoint['IsOverriden'] == 1, 'Yes',
                '');
//if it's a string
var over = When($datapoint['IsOverriden'] == '0', 'No',
                $datapoint['IsOverriden'] == '1', 'Yes',
                '');
dwold
by
Frequent Contributor

@KenBuja Thank you!

0 Kudos
dwold
by
Frequent Contributor

@KenBuja If I wanted to hide the Override line if the value is 0 would that be done through an if statement? Or can that still be done using the when statement?

Showing only records that have 1/yes

dwold_0-1692388895593.png

dwold_1-1692388927825.png

 

 

0 Kudos
KenBuja
MVP Esteemed Contributor

How are you constructing the text block?

0 Kudos
dwold
by
Frequent Contributor

@KenBuja I removed the == 0, 'No', line thinking the list would remove/hide the 0 values, but it still read Score override:  (because that is part of the text block)

(didn't think it would be that easy but gave it a shot)

Doing this:

dwold_0-1692629954275.png

and then:

{expression/icon}

{AssesmentName}

Created on {expression/create}

Created by {Creator}

Score override: {expression/over}

0 Kudos
KenBuja
MVP Esteemed Contributor

Instead of putting "Score override: " in the text block, add that in the expression only if the value is "Yes"

If ($datapoint['IsOverriden'] == 1) return 'Score override: Yes';
dwold
by
Frequent Contributor

Great, thank you!

0 Kudos
dwold
by
Frequent Contributor

@KenBuja I'm new to arcade so I don't think I am doing something right. When I remove the text block that line is deleted (even values with 1/yes). Does the return call look in the right spot? See anything that I am doing wrong?

dwold_0-1692704093940.pngdwold_1-1692704115654.pngdwold_2-1692704150924.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

I'm sorry, I was incorrect. That should be

 

If ($datapoint['IsOverriden'] == 1) var over = 'Score override: Yes';

 

Keep 'over' in the attributes and {expression/over} in the template