Calculating a field to list another field's name

890
6
07-10-2020 11:01 AM
KaydenSim
New Contributor II

Hi Esri community, 

I have two fields that represent different event categories, each denoting the year a given event category occurred. 

I want to calculate a new field that will list the field name of the event type with the maximum value (latest year). 

Is there any way I can do this? 

For example:

Event_type1 ;  Event_type2,  last_event_type

     1984                1972            event_type1 

Thanks for any help!!

- Also, I posted this in the Python community because I thought there might be a script that could perform this action, but if there is a better geonet community for this question please let me know. 

0 Kudos
6 Replies
DavidPike
MVP Frequent Contributor

What do you want to happen if two events happen in the same year? Can you give an example row in your dataset?

0 Kudos
KaydenSim
New Contributor II

If two events happen in the same year I would want the field to have the name of a third separate column. 

0 Kudos
MattDriscoll1
New Contributor II

Quickly off the top of my head something like this.  Are you trying to do this in a field calculator or in a script?

Event_one = "Event_type1"
Event_two =  "Event_type2"
Last_Event = "last_event_type"

if Event_one > Event_two:
   Last_Event = "Event_type1"
else:
   Last_Event = "Event_type2"‍‍‍‍‍‍‍‍
0 Kudos
KaydenSim
New Contributor II

Thanks for this!!

Preferably in field calculator, but if a python script is the only way to do it, that will have to do. 

0 Kudos
DavidPike
MVP Frequent Contributor

I'd do it in field calculator with something along the lines Matt laid out, using a code block.

0 Kudos
MatthewDriscoll
MVP Alum

Try Calculating the field using Expression Type Python.

Expression:

 

Value(!Event_type1!,!Event_type2!)‍‍‍‍

Code Block:

def Value(x,y):
    if (x > y):
        return "Event_type1"  
    else:
        return "Event_type2"‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

0 Kudos