ArcGIS Field Calculator – How to Count Occurrences Grouped by Another Field

arcgis-10.1arcgis-desktopfield-calculatorstatistics

Is there a way of calculating the number of unique text strings in a field in ArcGIS 10.1? I have a number of repeated strings in this field, but would like to calculate the number of unique strings in a field based on groupings from another field.

E.g – Current table:

Field 1    Field 2   
Apple      Green     
Apple      Red       
Apple      Red
Citrus     Yellow
Citrus     Green
Citrus     Orange
Citrus     Orange

Result:

Field 1    Field 2
Apple      2
Citrus     3

Best Answer

Two "summarize" operations will do it. This is a basic operation requiring no extra licenses.

First compute a field that concatenates Field1 and Field2. (If your table is not editable or should not be modified, do these operations on a copy of it.) It's a good idea to delimit the concatenation; here I have used "|" as a delimiter.

Field 1    Field 2    Concatenation
Apple      Green      Apple|Green
Apple      Red        Apple|Red
Apple      Red        Apple|Red
Citrus     Yellow     Citrus|Yellow
Citrus     Green      Citrus|Green
Citrus     Orange     Citrus|Orange
Citrus     Orange     Citrus|Orange

The summary of the Concatenation field, retaining the first occurrence of Field1, will look like

Concatenation  Field1  Count
Apple|Green    Apple   1
Apple|Red      Apple   2
Citrus|Yellow  Citrus  1
Citrus|Green   Citrus  1
Citrus|Orange  Citrus  2

Finally, the summary of Field1 obtains what you want:

Field1 Count
Apple  2
Citrus 3
Related Question