Select to view content in your preferred language

Get number of rows with a specific value in Model Builder

1891
6
Jump to solution
02-03-2018 04:46 AM
MarkHenigan
Emerging Contributor

Hi,

I need to get a number of rows with value "1" (ICOUNT field in attached image) throug the calculate value function in model builder. What will be the Expression and Code Block??

Thanks

Mark

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

The count will yield one value for the table. What will you do with this value? Fill all records of a field with this value? You could use Select Layer By Attribute—Help | ArcGIS Desktop and specify the query ICOUNT = 1 followed by Get Count—Help | ArcGIS Desktop . This will yield a single value. What do you want to do with this value?

View solution in original post

6 Replies
XanderBakker
Esri Esteemed Contributor

The count will yield one value for the table. What will you do with this value? Fill all records of a field with this value? You could use Select Layer By Attribute—Help | ArcGIS Desktop and specify the query ICOUNT = 1 followed by Get Count—Help | ArcGIS Desktop . This will yield a single value. What do you want to do with this value?

MarkHenigan
Emerging Contributor

I have a model where I'm going to use this value later, to calculate another parameter.

0 Kudos
curtvprice
MVP Esteemed Contributor

Re: How to determine number of records using arcpy.da.SearchCursor

would be what you could use with Calculate Value, but as discussed in that thread GetCount is almost as fast for a few records and faster for big tables. I vote for Xander's suggestion.

MarkHenigan
Emerging Contributor

Thanks! Xander's method works, I just thought with "calculate value" it will be more elegant

0 Kudos
XanderBakker
Esri Esteemed Contributor

Glad it worked! Could you mark the post that best answered your question as the correct answer?

To calculate a value with the Field Calculator will return a value for each record. Since you want to have the result of the count of all values equal to one, only the last and after the last value of one the correct value would be obtained. So you need to loop through all the record to obtain the value and then loop again to write that value to each record. It is possible and if you want to have that value in a field it is probably a good way to go as suggested by curtvprice 

0 Kudos
curtvprice
MVP Esteemed Contributor

To calculate a value with the Field Calculator will return a value for each record.

Xander, I believe Mark was planning on using the Calculate Value tool, not Calculate Field.

It should be mentioned for the good of the thread that Calculate Value is a very powerful tool that allows you to do a lot in Model Builder that would be difficult otherwise, by allowing you to a) execute a python snippet and b) return a single value cast to any data type needed to "pipe" into the parameter of another tool. Though for this use case you definitely get the cookie - Select Layer by Attribute or Make Feature Layer connected to Get Count is the best solution for sure.