Field calculate a table name into a field.

333
2
03-28-2023 11:31 AM
Carlos_Par
New Contributor II

I am trying to create a Year Field so I can combine multiple datasets into one then filter them by year.  The individual datasets only have the year in their name(example: table_2019).  Does anyone know how I can bring the name of the table in as a value in field calculator?

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

AFAIK, it's not possible to get the name of the table in the Calculate Field tool. But you can throw together a litte script where you get the year from the table name and then use that to calculate a new field:

arcpy.env.workspace = "G:/ArcGIS/.../my_database.gdb"
datasets = ["TestPoints_2019", "TestPoints_2020"]
for ds in datasets:
    year = ds.split("_")[-1]
    arcpy.management.CalculateField(ds, "Year", year, "PYTHON3")

Have a great day!
Johannes
0 Kudos
Carlos_Par
New Contributor II

Thank you @JohannesLindner  I will try that.

0 Kudos