HOW TO

Compare values from multiple fields and return the highest and lowest values of a pop-up using Arcade expression in ArcGIS Online

Last Published: March 10, 2022

Summary

In ArcGIS Online, custom expressions written in the Arcade expression language can be used to configure pop-ups. Expressions can be used to generate new data with a reference to an existing field in a layer that has multiple values.

This article provides the steps to return the highest and lowest values in a field of a pop-up via ArcGIS Online Map Viewer. In this example, two new fields (Low Ratio Year(s) and Top Ratio Year(s)) are added to the pop-up by using the Ratio of Female to Male in Primary Education, 2006 to 2016 fields, as reference to display the lowest and highest ratio years for each point symbol.

Procedure

  1. Open the map in Map Viewer. Click Layers on the Contents (dark) toolbar and select the <layer name> with the pop-up for editing.
The Map Viewer Contents (dark) toolbar with the Layers tab
  1. Click Configure pop-ups on the Settings (light) toolbar and click Manage expressions.
The Map Viewer Pop-ups pane to navigate to the Map Viewer Pop-up expressions pane
  1. Click + Add expression to open the Arcade expression editor window.
The Map Viewer Pop-up expressions pane with the Add expression icon
  1. Specify the following Arcade expression in the Expression window.
Note:
The data displayed in ArcGIS Online may have additional decimals that are rounded in the table by default.
  • Return the highest value from a number array.
//specify the field names to reference to
var <variableName1> = [
    $feature.<field_Name1>,
    $feature.<field_Name2>,
    $feature.<field_Name3>,
    $feature.<field_Name4>,
    $feature.<field_Name5>,
    $feature.<field_Name6>,
    $feature.<field_Name7>,
    $feature.<field_Name8>,
    $feature.<field_Name9>,
    $feature.<field_Name10>,
    $feature.<field_Name11>
]

var <variableName2> = Max(<variableName1>)

var <variableName3> = []

//Assigning the highest value
for (var <v> in <variableName1>){
    if (<variableName1>[<v>] == <variableName2>){
        var <variableName4> = Decode(
            <v>,
            0, '<field_display_Name1>',
            1, '<field_display_Name2>',
            2, '<field_display_Name3>',
            3, '<field_display_Name4>',
            4, '<field_display_Name5>',
            5, '<field_display_Name6>',
            6, '<field_display_Name7>',
            7, '<field_display_Name8>',
            8, '<field_display_Name9>',
            9, '<field_display_Name10>',
            10, '<field_display_Name11>',
            ''
        )

        Push(<variableName3>, <variableName4>)
    }
}

return Concatenate(<variableName3>, TextFormatting.NewLine)
  • Return the lowest value from a number array.
//specify the field names to reference to
var <variableName1> = [
    $feature.<field_Name1>,
    $feature.<field_Name2>,
    $feature.<field_Name3>,
    $feature.<field_Name4>,
    $feature.<field_Name5>,
    $feature.<field_Name6>,
    $feature.<field_Name7>,
    $feature.<field_Name8>,
    $feature.<field_Name9>,
    $feature.<field_Name10>,
    $feature.<field_Name11>
]

var <variableName2> = Min(<variableName1>)

var <variableName3> = []

//Assigning the lowest value
for (var <v> in <variableName1>){
    if (<variableName1>[<v>] == <variableName2>){
        var <variableName4> = Decode(
            <v>,
            0, '<field_display_Name1>',
            1, '<field_display_Name2>',
            2, '<field_display_Name3>',
            3, '<field_display_Name4>',
            4, '<field_display_Name5>',
            5, '<field_display_Name6>',
            6, '<field_display_Name7>',
            7, '<field_display_Name8>',
            8, '<field_display_Name9>',
            9, '<field_display_Name10>',
            10, '<field_display_Name11>',
            ''
        )

        Push(<variableName3>, <variableName4>)
    }
}

return Concatenate(<variableName3>, TextFormatting.NewLine)
  1. Rename the New expression and click OK.
The Map Viewer expression window to specify the Arcade expression
  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 expressions
  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
  1. Check the expression field and click Done.
The Map Viewer Select fields pane

The image below demonstrates the pop-up display without the Arcade expression.

The Map Viewer pop-up without the Arcade expression

The image below demonstrates the pop-up display with the Arcade expression.

The Map Viewer pop-up with the Arcade expression enabled

Article ID: 000027238

Software:
  • ArcGIS Online

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