Select to view content in your preferred language

Field Calculator for not null fields

6100
11
Jump to solution
11-08-2018 10:38 AM
AndrewIngall1
Occasional Contributor

I am trying to use the field calculator to concatenate various fields into one new field.  The ArcGIS Arcade Guide gives the following example

Concatenate(['red', 'blue', 'green'], '/')

which gives red/blue/green.  This works fine when all of the fields contain a value, but how can i concatenate only the fields that are not null

I am trying to concatenate address details , so for example 

field1 = building name

field2 = building number

field3 = road name

field4 = area

field5 = town

in my example the building name or area could be null, so i end up with:-

,12,A Road,,Town - so i need to remove the additional field separators ','

Thanks for any help

Tags (1)
11 Replies
JoshuaBixby
MVP Esteemed Contributor

Not sure how it could get much simpler.  If the passing of field names is removed, the code boils down to:

', '.join([str(i) for i in [ ] if i])

That is pretty simple and compact.  The bulk of the line is in field names, and you can't remove them.

0 Kudos
KevinN_CSJ
Occasional Contributor

I know this thread is old, but in case anyone comes across this searching for this solution as I did, I got the code to work by replacing the full quotes "" with single quotes '' on line 17 when used in an AGOL custom field

0 Kudos