Select to view content in your preferred language

Iterate Field Values - Using Value in Select Layer By Attribute

8521
25
Jump to solution
04-12-2013 07:21 AM
BJMalone
Emerging Contributor
I am trying to build a model that iterates through the unique values of a field, then selects each of those values and calculates another field for that selection.  I'm having trouble passing the Value output from the iteration to the Select Layer by attribute tool.  For example each iteration would output a unique number, lets say 2104, then the Select Layer by Attribute tool would use 2104 as the selection criteria.  The model would iterate through all of the unique values calculating the field for each selected set.  I can't figure out how to get the Select Layer by attribute to use the output Value of the iteration.  Any help would be appreciated.  I am very new to model builder.
0 Kudos
1 Solution

Accepted Solutions
MatthewPayne
Esri Contributor
Try this one.  Be sure to extract the contents from the zip folder first.

Matt

View solution in original post

0 Kudos
25 Replies
MatthewPayne
Esri Contributor
BJ,

Take a look at how the attached model is set up.  I set the input layer as input to both the Iterate Field Values iterator and the Select Layer by Attribute tool.  I used the Value output from the iterator as part of the expression in the Select Layer by Attribute tool.

Matt
0 Kudos
BJMalone
Emerging Contributor
Matt,

Thanks for your help on this.  I am still having an issue.  How can I get the Expression for the Select Layer By Attribute to pull in the Value output from the Iterate Field Values?  The expression needs to be something like FieldName = Value for each iteration.

Thanks
0 Kudos
BJMalone
Emerging Contributor
I used "GridNumber" = %Value% but it does not select anything.
0 Kudos
MatthewPayne
Esri Contributor
"GridNumber" = %Value% is correct.  That is what worked on my end with my data.  What is the field type of GridNumber?  I used a short integer field.  Also, what is the 'Data Type (optional)' set to inside the Iterate Field Values parameter window?  Mine is set to String.

Matt
0 Kudos
MatthewPayne
Esri Contributor
Also, feel free to attached your current model and input data file.  I can take a look at it for you.

Matt
0 Kudos
BJMalone
Emerging Contributor
I think I have everything set as you have described, however I'm still not getting a good result.  I have attached the model and the data if you wouldn't mind taking a look.  Thanks
0 Kudos
MatthewPayne
Esri Contributor
I was able to get this to successfully run on my end with a basic field calculation.  The issue seems to be within your code block possibly, I'll take a look.  What is the outcome you are expecting to see?

Matt
0 Kudos
BJMalone
Emerging Contributor
For all features with a "GridNumber" that is the same, the "FeatureNumber" field would be get an incremental value of 1 through n.  For example if 5 features have a "GridNumber" = 3105, then "FeatureNumber" would be 1, 2, 3, 4, and 5.
0 Kudos
MatthewPayne
Esri Contributor
In the Calculate Field tool, try changing the Expression Type to PYTHON_9.3.  This change allowed the model to run successfully on my end with your exact code block.

Matt
0 Kudos