Replace a number with a string in an Arcade Expression

5002
4
Jump to solution
12-21-2017 02:14 AM
AnninaHirschi_Wyss1
Occasional Contributor III

I would like to see in my pop up e.g. "N/A" for all 0 values in a numeric field trying to do:

var salinity = $feature.d_sal_max;

IIF(salinity == 0,'N/A',salinity);

This leaves all 0 values empty (instead of showing "N/A") in the pop up and returns the actual value for all other values. Putting ' ' around the 0 doesn't make a difference.

The Expression:

var salinity = $feature.d_sal_max;

Replace(salinity, 0, 'N/A');

Replaces all 0 with "N/A", meaning "0.111" will appear as "N/A.111".

Any ideas?

Thanks,

Annina

0 Kudos
1 Solution

Accepted Solutions
AnninaHirschi_Wyss1
Occasional Contributor III

Thanks Carmel and Dan for these immediate replies!

What I missed was to configure the expression as string (within the "Configure Attributes"-window). And as the values have too many decimals, I added a ROUND() to the variable.

Now it works like a charm.

View solution in original post

4 Replies
CarmelConnolly
Esri Regular Contributor

Hi Annina, 

How about:

IIf($feature.d_sal_max == 0, "N/A", $feature.d_sal_max)

More information here: What’s New in Arcade (June 2017) | ArcGIS Blog 

Carmel

DanPatterson_Retired
MVP Emeritus

plus the functional reference is a useful link

AnninaHirschi_Wyss1
Occasional Contributor III

Thanks Carmel and Dan for these immediate replies!

What I missed was to configure the expression as string (within the "Configure Attributes"-window). And as the values have too many decimals, I added a ROUND() to the variable.

Now it works like a charm.

YankiYankito
New Contributor

Greetings community:

Have a similar case. Have an excel table with a colum with numeric codes and another colum with a description, for example:

34.................Blue car

35.................Green Carpet

36.................Brown vaccun

Is there a way i could use Model Builder to automatically substitute the numeric code with the descriptor once the excel table has been improted and appended to a layer's atribute table?

Thank you.

0 Kudos