# "CountIf" or alternative function in ArcMap field calculator?

Within ArcMap 10.3 field calculator, I am looking to count the number of features in a column that match the current value, and output that count. Ideally, the output would look like this:

Number      Count
2000              2 (because there are only 2 counts of 2000 in the number column)
2000              2 (because there are only 2 counts of 2000 in the number column)
2001              1 (because there is only 1 count of 2001 in the number column)
4333              1 (because there is only 1 count of 4333 in the number column)

I accomplished this in excel using the Visual Basic Countif() function, but I just don't know how to call a full array of values from the Number column.

This is generally not something that should be done using the Field Calculator (although by using a cursor you can do it, it is better to create a standalone Python script). The easiest approach is simply to run summary statistics on the column, join the column to the summary output, and calculate the summary count values over to the count field in the original.

The cursor approach basically uses a dictionary in memory to do the counting and then run a second update cursor to update the count column from the dictionary. See the last example in my Blog on Turbo Charging Data Manipulation with Python Cursors and Dictionaries.

You can use the cursor approach in the Field Calculator, but you have to make the dictionary a global variable and generate it by reading all the records of the cursor only once as you calculate the first feature. All other features just reference the count already stored in the dictionary built for the first feature. The principals I am describing also apply to building a label from a dictionary and is demonstrated in my Blog on Creating Labels with Related Table Data.

• This worked! Summary Statistics was far easier than the cursor approach. Dec 29, 2015 at 21:10
• The cursor approach is really only indispensable when you want to match a large amount of records between two different data sources. It is incredibly fast and will out perform the join and field calculation by a huge amount if the two data sources are large, Dec 29, 2015 at 22:25

You could try using the "Summarize" command.

It will do this count, but it will generate another new table.

You can use this command by clicking with the right button in the field to be counted them choose "Summarize", select any other fields that you may want to average, sum... then give the name of the new table.

You can also add this result in the map and, by join and relations, put this information again in your geographic data.