Select to view content in your preferred language

Calculate Field from a one to many relationship class

5440
4
01-10-2014 11:17 AM
NicholasGlover
Deactivated User
Hello Everyone,

I have been trying to build a model that will take information from a Frequency table and put into my feature class. My problem is that I cannot join the two tables because the table would have a one to many relationship. I've decided the best way to place the information into the feature class would be to use Calculate Field. The problem is that I have no idea how to code with python to make this cross two different tables using Calculate Field. I have attached how my tables look so that you guys may be able to give me suggestions. The common field that these table share is "Switch Number" and "SwitchName"  Sorry this may seem a little confusing, but I'm rather confused myself right now. I have attached some pictures of my attribute tables.
0 Kudos
4 Replies
JoshuaChisholm
Frequent Contributor
Hello Nicholas,

Joins like that can be very confusing. As far as I know, the "Field Calculator" can't read in from multiple tables.

Could you reverse the join. In other words, join the smaller table to the Frequency table (this would require the smaller table having a unique "Switch Number" field).

Alternatively we can get into python scripting to join and do stuff with the data there. What information are you trying to get out of the Frequency table?
0 Kudos
by Anonymous User
Not applicable
Original User: ndglover21

Thanks for the reply Joshua,

I'm trying to figure out how many times a specific type of phase (A, B, C and so forth) is occurring on a line. The unique identifier that I'm using  for these lines is Switch Name. What I want to be able to do is grab the information about how many times the phase occurs on the line (That is stored in the frequency table), and put that information into the line were A_Total, B_Total, and so forth.

For example If I go over to the FrequencyTable I see that my phaseCode information is all in one column. Next to the phaseCode column is information about how many times the event happens on the individual line. If we take a look at Switch Name 407 we see that 'A' occurs 5 times. I want to be able to take that frequency of that 'A' and put it into 'A_Total' in the FeatureClassTable, but I only want the 'A' information for the Switch Name (Accidentally labeled as Switch number in the FeatureClassTable) 407 to go into that. I want to be able to to this to all my totals in each row of Switch Names.
0 Kudos
JoshuaChisholm
Frequent Contributor
Hello Nicholas,

Sorry for the late reply.
Thanks for the clear explanation. I think I understand what you're trying to do. Let me know if I miss the mark.

How I would handle this join involves two steps:
1) Sum up the FrequencyTable by Switch Name and get a count for each phase type. The desired result is a table of SwitchName going down with the associated counts. We're shooting for something like:
SwitchName,A_Count,B_Count,AB_Count,AC_Count,ABC_Count
406,84,0,2,55,7
407,5,0,12,0,0
408,2,31,3,0,0

This step is actually pretty difficult (unless I'm missing something) and you could use a data management software. A pivot table should do the trick (in excel or arcmap). I think the ArcMap version requires special license (which I don't have). It's pretty easy to do it in excel (see screenshot below):
i) get your data into excel
ii) 'Insert' tab > 'Pivot Table'
iii) select data
iv) check on the SwitchName, phaseCode and ObjectID (or and other field with no empty values)
v) move phaseCode to Column Labels, move SwitchName to Row Labels and move ObjectID to Values
vi) click on ObjectID under Values and click 'Value Field Settings'. Make sure you are getting a count and not a sum
vii) make sure you total is what you expected (total number of records in Frequency table)

Alternatively you could use python. I was playing around with it and one way to do it is to make a dictionary of dictionaries. The main dictionary would have a key of SwitchName and a value of another dictionary. The inset dictionary would have a key of phaseCode and a value of a count of occurrences. The script ended up being pretty long and bloated, so I think excel is a better bet (if possible).

2) Join the table from 1) to the line shapefile with SwitchName. It should be a one-to-one join.

Let me know if this works for you (or if it works at all). Good luck!
0 Kudos
by Anonymous User
Not applicable
Original User: erictwendell

Hello Everyone,

I have been trying to build a model that will take information from a Frequency table and put into my feature class. My problem is that I cannot join the two tables because the table would have a one to many relationship. I've decided the best way to place the information into the feature class would be to use Calculate Field. The problem is that I have no idea how to code with python to make this cross two different tables using Calculate Field. I have attached how my tables look so that you guys may be able to give me suggestions. The common field that these table share is "Switch Number" and "SwitchName"  Sorry this may seem a little confusing, but I'm rather confused myself right now. I have attached some pictures of my attribute tables.


Yes hua19 is correct, even I believe that you should use a data management software for the same. For this you can also use any open source ETL tool provider or you can also contact any third party's Master Business Administration software that can be configured as per your requirements.
0 Kudos