Select to view content in your preferred language

Concatenate Unique values (only)

860
1
07-13-2023 06:12 PM
Status: Open
Labels (1)
jakek
by
New Contributor III

@KoryKramer @DrewFlater  The implementation of the concatenate option has been great, thank you, but what I see now is the need for a "concatenate UNIQUE" option.  See this tech support  example: https://support.esri.com/en-us/knowledge-base/how-to-concatenate-field-values-using-a-case-field-in-....

It lists the same value multiple times (i.e. 111).  I would like to see the option to only show unique values (111 would only show once).  My use of this today resulted in the same value populated numerous times making the field width in excess of 500 characters.  Would it be possible to add a checkbox option to only return unique values?

Previous idea: https://community.esri.com/t5/arcgis-pro-ideas/arcgis-pro-2-6-a-geoprocessing-tool-to-concatenate/id...

 

1 Comment
MarkBryant

You can run a field calculator on the concatenated field.

 

 

def sortValues(the_value, delimiter=','):
    """Sort a separated value into an order
    Useful to run on ArcGIS processes where there is no control on returned values.
    For example SpatialJoin, JOIN_ONE_TO_ONE, with FieldMapping Merge Rule = Join
    """
    if the_value == None:
        return the_value

    # Create a Python list by splitting the string on the delimeter
    the_list = the_value.split(delimiter)
    # unique elements of the list using set()
    the_set = set(the_list)
    # turn the set back to a list
    the_list = list(the_set)
    # Sort the list
    the_list.sort()

    # Reassemble the string from the sorted list
    rval = delimiter.join(the_list)
    return rval