HOW TO

Return specific fields containing a string for further calculation in ArcGIS Pro

Last Published: October 18, 2022

Summary

In ArcGIS Pro, Arcade expressions can be used to identify specific fields with similar field names. The identified fields can be used for further calculations. This article provides an example and instructions using Arcade expressions to return the fields containing a string for further calculation in pop-ups for ArcGIS Pro.

The field values from the following fields (2006 Ratio of Female to Male in Primary Education, 2007 Ratio of Female to Male in Primary Education, 2008 Ratio of Female to Male in Primary Education, and 2009 Ratio of Female to Male in Primary Education) are identified to calculate the minimum and maximum values.

The image below shows a standard pop-up without the minimum and maximum values.

The standard pop-up in ArcGIS Pro without the minimum and maximum values on display

Procedure

  1. Start ArcGIS Pro and open the project.
  2. In the Contents pane, right-click the feature class and click Configure Pop-ups to open the Configure Pop-ups pane.
Opening the Configure Pop-ups tool of the feature class from the Contents pane
  1. Click Expressions and click New.
  2. In the Expression Builder tool dialog box, configure the following parameters for each of the Arcade expression:
    1. For Name, rename the new expression.
    2. For Title, specify a title for the new expression.
    3. Specify the following Arcade expression in the Expression section:
    • Define the variable for the fields, field values, and all_fields.
var <variableName> = [];
var <variableName1> = [];
var <variableName2> = Schema($feature)['fields'];
  • Iterate through the fields and specify the field name character or character location to be identified. The use of the (Left(), Mid(), or Right()) functions depends on the location of the similar characters available for the group of field names in the attribute table. In this example, the Mid() function is used, since the common character similar to the targeted fields is 0.
for (var i in <variableName2>){
    var <variableName3> = <variableName2>[i]
    var <variableName4> = <variableName3>['name']
    if (Mid(<variableName4>, 5, 1) == '0'){
        Push(fields,<variableName4>)
        Push(<variableName1>, $feature[<variableName4>])
    }
}
  • Specify the value to be returned using the required mathematical function. In this example, Max() is used to return the highest value in a given array.
return max(<variableName1>)

The code below shows the full working script.

var fields = [];
var values = [];
var all_fields = Schema($feature)['fields'];
for (var i in all_fields){
    var field_dict = all_fields[i]
    var x = field_dict['name']
    if (Mid(x, 5, 1) == '0'){
        Push(fields,x)
        Push(values, $feature[x])
    }
}

return max(values)
  1. Click Verify to test the expression. If there are no errors, click OK.
Specifying the Arcade expression in the Expression Builder tool dialog box
  1. In the Configure Pop-ups pane, click the Back icon.
  2. Click Fields > Edit pop-up element to configure the fields to be shown in the pop-up.
Navigating to the Edit pop-up element pane in the Configure Pop-ups pane
  1. In the Fields Options pane, uncheck the Only use visible fields and Arcade expressions check box and select the required fields to be shown in the pop-up.
Selecting the fields to be shown in the pop-up

The image below shows the minimum and maximum values in the pop-up after using the Arcade expression.

The updated pop-up with minimum and maximum values

Article ID: 000028428

Software:
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options