Concatenate fields based on If/then statements

433
1
08-26-2022 03:46 PM
Labels (2)
ChadTheismann
New Contributor II

Hello, I'm looking for some assistance writing a formula that concatenates addressing fields if they are not null.  I have addresses broken out in individual text fields such as owner, address number1, address number 2, street direction, street name, street type, unit, city, and zip. All fields are text fields.   In the address fields, not all values are populated.  I only want values from fields that are populated.  If you couldn't tell, I am not experienced with VB or python. My database has ~50000 records.   I am using ArcMap 10.8.   Is there any way populate a concatenated site address field from populated address fields?

Example: 

OWNER

SITUS_ADR1

SITUS_ST

SITUS_ST1

SITUS_TYPE

SITUS_CITY

SITUS_ST

SITUS_ZIP

J AND J DOE

1234

S

FIRST

AVE

PORT

AB

99999

CONCATENATED SITUS= J AND J DOE, 1234 S FIRST AVE, PORT, AB, 99999

MR. ABC

1111

<no value>

SEA

DR

PORT

AB

99999

CONCATENATED SITUS= MR. ABC, 1111 FIRST AVE, PORT, AB, 99999

XYZ

2222

<no value>

HWY Z

<no value>

PORT

AB

99999

CONCATENATED SITUS= XYZ, HWY Z, PORT, AB, 99999

0 Kudos
1 Reply
VinceAngelo
Esri Esteemed Contributor

Yes, it's certainly possible, though I suggest you make the effort to learn Python (which is the easiest computer language to learn, ever).

Calculate Field field reference syntax is a bit more obtuse, so you want to follow the documentation carefully. That will result in a code block that looks like this:

def concatenateFields(f1,f2,f3,f4,f5,f6,f7):
    l = []
    if f1: l.append(f1)
    if f2: l.append(f2)
    if f3: l.append(f3)
    if f4: l.append(f4)
    if f5: l.append(f5)
    if f6: l.append(f6)
    if f7: l.append(f7)
    return ', '.join(l)

and an expression of:

concatenateFields(!SITUS_ADR1!,!SITUS_ST!,!SITUS_ST1!,!SITUS_TYPE!,!SITUS_CITY!,!SITUS_ST!,!SITUS_ZIP!)

- V

0 Kudos