HOW TO

Identify specific fields containing a string for further calculation in Portal for ArcGIS and ArcGIS Online Map Viewer

Last Published: October 12, 2022

Summary

In Portal for ArcGIS and ArcGIS Online Map Viewer, Arcade expressions can be used to identify specific fields with similar field names for further calculations.

This article provides an example and instructions for using Arcade expressions to identify and calculate specific fields containing a string in pop-ups of Map Viewer.

In this example, an Arcade expression is used to identify the fields for the Ratio of Female to Male in Primary Education from 2006 to 2009, and calculate the minimum value.

The image below shows a standard pop-up without the minimum value.

The standard pop-up in ArcGIS Online Map Viewer without the minimum and maximum values on display

Procedure

  1. Open the map in Map Viewer. Click Layers on the Contents (dark) toolbar, and select the layer with the pop-up for editing.
  2. On the Settings (light) toolbar, click Configure pop-ups > Options > Attribute expressions.
  3. Click + Add expression to open the Arcade expression editor window.
  4. Specify the following Arcade expression in the Expression window.
    1. Define the variable for the fields, field values, and all_fields.
var <variableName> = [];
var <variableName1> = [];
var <variableName2> = Schema($feature)['fields'];
  1. Iterate through the fields and specify the field name character or characters location to be identified. The functions to be used (Left(), Mid(), or Right()) 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 that is similar for the targeted fields is 0.
The attribute table showcasing the field names in ArcGIS Online Map Viewer
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>])
    }
}
  1. Specify the value to be returned using the required mathematical functions. In this example, the min() function is used to return the lowest value in a given array.
return min(<variableName1>)
Note:
Refer to ArcGIS Arcade: Mathematical Functions for other mathematical functions to calculate the given array.

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 min(values)
  1. Rename the expression, and click Test to test the expression. If there are no errors, click OK.
Specifying the Arcade expression in the Map Viewer Expression window
  1. Click the Previous button above the newly created Arcade expression in the Pop-up expressions pane.
The Map Viewer Pop-up expressions pane with the newly added expression
  1. Click Fields list to expand the list of fields displayed in the pop-ups, and click Select fields.
The Map Viewer Pop-up expressions pane displaying the location of the Fields list section
  1. Check the expression field, and click Done.
The Map Viewer Select fields pane to select fields to be displayed in the pop-up

The image below shows the minimum value of the identified fields in the pop-up after using the Arcade expression.

The updated pop-up with minimum values

Article ID: 000028347

Software:
  • ArcGIS Online
  • Portal for ArcGIS

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