Select to view content in your preferred language

Arcade Expression Help - If value in one field is NULL, then make the value in a different field a specific value.

2308
7
Jump to solution
12-01-2023 10:46 AM
JamesBooth
Occasional Contributor

JamesBooth_0-1701456150728.png

I'm getting an error with the expression in the image above. I'm basically trying to set the UNIT value to be either a "Y" or "N" depending on the value of the UNIT_NUM field (UNIT NUMBER alias). If there is no values (NULL) in the UNIT, then I want the UNIT value to be "N", otherwise I want it to be "Y". Any help with my syntax is greatly appreciated. I'm new to Arcade! 🙂 Syntax is also written below in case image doesn't come through:

var a = $feature.UNIT_NUM
var b = $feature.UNIT
var c = "Y"
var d = "N"

return IIf(!IsEmpty(a), d,
else{return c}

0 Kudos
2 Solutions

Accepted Solutions
JamesBooth
Occasional Contributor

Above did work thank you! The rule was validated and is accepted.

My only problem now is that when I saved the rules, all of my address points dissapeared! Every single one. But they are still in the attribute table! I have the symbology to be unique value, so it's not a symbology issue. I went back to my attribute rules and deleted that new rule, and the points reappear. Really strange!

In my Address points feature class, I have a large number of fields. Two of them are UNIT and UNIT_NUMBER. Many of my existing address points have values for the UNIT_NUMBER. Many of them however are also Null values. I want the existing addresses and any new addresses to auto-populate the UNIT field with a Y or a N. I want the UNIT value to be "Y" if there are is a unit value in the UNIT_NUMBER field. And I would like the UNIT value to be "N" if the UNIT_NUMBER is Null.

I'm really not sure why the new rule, which seems to be valid, would visually remove ALL of my address points. ESRI bug? Or am I just missing something obvious?

View solution in original post

0 Kudos
CodyPatterson
Frequent Contributor

Glad to hear it's working! That is very odd though, I'm not sure why it would remove all visual indications of what is occurring. As DavidPike mentioned below, you could try to use the calculate field expression if you aren't already, and here is another broken up section of what you could place in there with some pseudo code:

var unitNumber = $feature.UNIT_NUM;

if (IsEmpty(unitNumber)) {return "N";}

else {return "Y";}

View solution in original post

0 Kudos
7 Replies
CodyPatterson
Frequent Contributor

I'm not sure if it'll be entirely helpful, but your IIf statement is missing an ending parenthesis, I believe it should be:

return IIf(!IsEmpty(a), d,

else{return c})

Could also try this:

return IIf(!IsEmpty(a), d, c);

I'm still looking into this though to see!

JamesBooth
Occasional Contributor

Above did work thank you! The rule was validated and is accepted.

My only problem now is that when I saved the rules, all of my address points dissapeared! Every single one. But they are still in the attribute table! I have the symbology to be unique value, so it's not a symbology issue. I went back to my attribute rules and deleted that new rule, and the points reappear. Really strange!

In my Address points feature class, I have a large number of fields. Two of them are UNIT and UNIT_NUMBER. Many of my existing address points have values for the UNIT_NUMBER. Many of them however are also Null values. I want the existing addresses and any new addresses to auto-populate the UNIT field with a Y or a N. I want the UNIT value to be "Y" if there are is a unit value in the UNIT_NUMBER field. And I would like the UNIT value to be "N" if the UNIT_NUMBER is Null.

I'm really not sure why the new rule, which seems to be valid, would visually remove ALL of my address points. ESRI bug? Or am I just missing something obvious?

0 Kudos
CodyPatterson
Frequent Contributor

Glad to hear it's working! That is very odd though, I'm not sure why it would remove all visual indications of what is occurring. As DavidPike mentioned below, you could try to use the calculate field expression if you aren't already, and here is another broken up section of what you could place in there with some pseudo code:

var unitNumber = $feature.UNIT_NUM;

if (IsEmpty(unitNumber)) {return "N";}

else {return "Y";}

0 Kudos
JamesBooth
Occasional Contributor

JosephRhodes2 suggestion to alter yours slightly worked and my points didn't disappear! Thanks Joseph! 

I'm having another issue now with the domain values set on the UNIT field of Yes or No. I perhaps accepted the solution too quickly lol! I will post another question. Thanks again

JosephRhodes2
Frequent Contributor

Oh shoot, I deleted my response because it looked like you had solved your issue already by the time I posted it. So here it is again for posterity:

var unitNumber = $feature.UNIT_NUMBER
var hasValue

IIF(IsEmpty(unitNumber), hasValue="N", hasValue="Y")

return hasValue
0 Kudos
DavidPike
MVP Frequent Contributor

is this calculate field?

0 Kudos
JamesBooth
Occasional Contributor

No this is an Arcade Expression set on a field within 'Attribute Rules', which I can get to by right-clicking on a feature layer and choosing Data Design > Attribute Rules.

0 Kudos