Select to view content in your preferred language

Calculate Field using IF and FIND arcade statement

304
5
Jump to solution
09-30-2024 06:55 AM
Labels (2)
JoshLay1
Emerging Contributor

I have two fields both are text and I am using the field calculator to calculate the empty field.  The populated field is name "groupNames" which contains values such as below.  The second field "agency" has no values and is where the calculated values are going.  I am trying to use arcade to find any values in the "GroupNames" field that contain the agency acronym such as "DDOT", then calculate the empty field with "DDOT" otherwise populate with "Undefined". I have been using the Arcade statements below but cannot get them to work.  Anyone have suggestions?    

IIF(Find('DDOT', $feature.groupNames)== 0, "DDOT", "Undefined")‍‍
IIF(Find('DPW', $feature.groupNames)== 0, "DPW", "Undefined")‍‍
IIF(Find('CFSA', $feature.groupNames)== 0, "CFSA", "Undefined")‍‍

JoshLay1_0-1727704272793.png

Thanks

Josh

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

If your goal is to get the agency name for each feature rather than finding the ones that are "DDOT", then you should use this.

When(Find('DDOT', $feature.groupNames) != -1, 'DDOT',
     Find('DPW', $feature.groupNames) != -1, 'DPW',
     Find("CFSA", $feature.groupNames) != -1, 'CFSA',
     // add all the other agency names you're looking for
     'undefined')

 

View solution in original post

0 Kudos
5 Replies
CodyPatterson
Frequent Contributor

Hey @JoshLay1 

Looks like you almost have it, -1 is the way to find if a result is not present, you may need to use a negation, try this out:

IIf(Find('DDOT', $feature.groupNames) != -1, "DDOT", "Undefined")

IIf(Find('DPW', $feature.groupNames) != -1, "DPW", "Undefined")

IIf(Find('CFSA', $feature.groupNames) != -1, "CFSA", "Undefined")

https://developers.arcgis.com/arcade/function-reference/text_functions/#find

Cody

0 Kudos
JoshLay1
Emerging Contributor

Thanks for the quick reply Cody.

I tried using your expression from line 1 as a test and received the error message below.

JoshLay1_0-1727706004429.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

If your goal is to get the agency name for each feature rather than finding the ones that are "DDOT", then you should use this.

When(Find('DDOT', $feature.groupNames) != -1, 'DDOT',
     Find('DPW', $feature.groupNames) != -1, 'DPW',
     Find("CFSA", $feature.groupNames) != -1, 'CFSA',
     // add all the other agency names you're looking for
     'undefined')

 

0 Kudos
JoshLay1
Emerging Contributor

Thanks Ken and Cody that worked! ESRI Community is awesome!

0 Kudos
KenBuja
MVP Esteemed Contributor

If you have a long list of agencies to check, this might be a better way. You can modify the array of agencies easier than making a long When function

var agencies = ["DDOT", "PEMA", "CFSA"];
var output = "undefined";
for (var j in agencies) {
  if (Find(agencies[j], $feature.groupNames) != -1) output = agencies[j];
}
return output

 

0 Kudos