0

What fields can the CalculateField_management expression parameter contain? I mean the parameters can be the fields what are in the output table, or can they be a field of another table too?

There are two tables:

  1. lot of fields and a field, what needed to be placed to other table.
  2. The joined table. It contains the field what comes from the previous table and all of the records has unique value in that certain field.

Now the task is to go through on the table 2's certain field and compute other field in that table 2, but I need to search for values in table 1. If a record's "certain field's" value is the same as table 2's "certain field" value, then I need the other field datas from table 1 to compute table 2's other fields.

Does the expression parameters need to be from only one table or can I refer to other table fields too?

I hope it's understandable.

  • 1
    Have you read the documentation? resources.arcgis.com/en/help/main/10.2/index.html#//… – ianbroad Jan 22 '15 at 23:52
  • Maybe I'm tired, but I can't see the answer in there. – greyline Jan 22 '15 at 23:55
  • @ian pastebin.com/ceAcTrae table is the linked table, shp is the original table. hsz == Helyrajziszam will be true even if their order is not the same? Because of the linking, right? – greyline Jan 23 '15 at 1:25
  • @PolyGeo I mean in the shp the "Helyrajziszam" field from top to bottom contains for example A, A, C, B, C, A, etc. and the tabl's "hsz" field contains A, B, C, D, E, etc. Will this hsz==Helyrajziszam true two times or just once? – greyline Jan 23 '15 at 1:36
  • I'm happy to look at extracts from your tables illustrated as graphics but not to retrieve the tables themselves from pastebin because in this instance I think they should be easy to illustrate that way. Also, it sounds like you may now be getting into one-to-many (or many-to-many) rather than many-to-one and one-to-one relationships so I think you should accept an answer on this and some of your previous questions and start a new one. – PolyGeo Jan 23 '15 at 1:42
1

This seems to be answered by the Calculate Field (Data Management) documentation:

When calculating joined data, you cannot calculate the joined columns directly. However, you can directly calculate the columns of the origin table. To calculate the joined data, you must first add the joined tables or layers to ArcMap. You can then perform calculations on this data separately. These changes will be reflected in the joined columns.

To learn how to refer to the joined columns in ArcPy I recommend reviewing How to Calculate Field in joined table using ArcPy?.

To your question "Does the expression parameters need to be from only one table or can I refer to other table fields too?", my answer (as above) is "No, you can calculate fields in the joined table too, as illustrated in How to Calculate Field in joined table using ArcPy?"

  • Well, it's okay. So I need to add the original table. But how to refer to the joined columns from that? – greyline Jan 23 '15 at 0:01
1

One option is to first use the Join Field tool.

Joins the contents of a table to another table based on a common attribute field. The input table is updated to contain the fields from the join table. You can select which fields from the join table will be added to the input table.

But, beware because this actually alters the input table- it's not a temporary join- it actually adds the fields you choose to the input table.

You could then easily use the Calculate Field tool on any column.

If you don't want to alter the original data, you could always make a copy of it, then run the Join Field tool on the copy.

  • It's not really a good solution. I mean I can't work on the input table's new join fields, because I can't initialize a searchcursor on that (the values aren't sorted and they are redundant in those joined fields). So I think I need to create a field calculator on the new table and somehow get the values of the original table, because I need to compute the new values from the original table. – greyline Jan 23 '15 at 0:07
  • Yeah, it won't work in every situation, but I'm not really sure what you're trying to do. If you're automating a task you perform a lot, or just a one time thing. If it's a one time thing, then this would probably be okay. I don't really understand why the Search Cursor wouldn't work though. Are you saying your join field is not 1:1? – ianbroad Jan 23 '15 at 0:21
  • There are two tables. 1: lot of fields and a field, what needed to be placed to other table. 2: The joined table. It contains the field what comes from the previous table and all of the records has unique value in that certain field. Now the task is to go through on the table 2's certain field and compute other field in that table 2, but I need to search for values in table 1. If a record's "certain field's" value is the same as table 2's "certain field" value, then I need the other field datas from table 1 to compute table 2's other fields. I hope it's understandable. – greyline Jan 23 '15 at 0:33
  • @gregtom6 Please use the edit button beneath your question to improve it with some of these clarifications. There is lots of useful information about How to ask a good question? but I think the most important is to keep revising your question bodies to make them more answerable rather than creating comment trails that may or may not be read by potential answerers. – PolyGeo Jan 23 '15 at 0:41
  • 1
    Yeah, you're wanting to do a very common task. Join two tables, and update a field(s) in one table based on a field(s) of another table. I think @Polygeo's second link in his answer is what you want. He edited his answer with an additional link, check it out. If I were you, I'd do the join in ArcMap, and use the field calculator to get your if/else statements down. Then convert that to a Python script, if that's what you're trying to do. – ianbroad Jan 23 '15 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.