Get Unique Values from a Field (Maybe Statistics Too?)
Getting unique values from a field in code can be done using the snippet provided by @RichRuh :
https://community.esri.com/t5/arcgis-pro-sdk-questions/getting-statistics-on-a-field/td-p/846351
But there are limitations. It took a while to find them, and it is very possible I didn’t find them all.
For our use case, the goal is to allow the user to use any layer of type FeatureLayer in the map’s contents as part of their work process. Streamlining the process through code involves asking them to select from 3 combo boxes: map layer name, then field name, and finally field value.
The code snippet from the post above throws exceptions when used with XY Event Layers, and as far as I can see, most feature layers that have a joined table (click link above for more information).
I think it might not be too hard to get something into the API that provides unique values since it is already done in the Pro GUI, for example, in the “Select By Attributes” tool. But I thought I would mention Statistics as well since it is very much related and worth considering at the same time. If anyone wants to see that in the API too, it would make sense to leave a comment with details about use cases for that.