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.
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.
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.
"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.
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
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?
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.
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.