HOW TO
In ArcGIS Online and Portal for ArcGIS Map Viewer, pop-ups configured by Arcade expressions with multiple statements can be used to display and sort field names and values across multiple fields of a feature. This makes it easier to determine which product or issue has the highest or lowest incident within a polygon. This article provides an example and instructions using Arcade expressions to create a pop-up with field names and values from multiple fields sorted in descending order in Map Viewer.
The image below shows a Map Viewer pop-up with each field and records separated.

function Comp (a, b) {
When(
IsEmpty(a[1]), -1,
IsEmpty(b[1]), 1,
Iif(a[1]>b[1], 1, -1)
);
};
var <variableName1> = [ ["<fieldName1>", $feature.<fieldName1>], ["<fieldName2>", $feature.<fieldName2>], ["<fieldName3>", $feature.<fieldName3>], ["<fieldName4>", $feature.<fieldName4>], ["<fieldName5>", $feature.<fieldName5>], ["<fieldName6>", $feature.<fieldName6>], ["<fieldName7>", $feature.<fieldName7>], ["<fieldName8>", $feature.<fieldName8>], ["<fieldName9>", $feature.<fieldName9>], ];
<variableName1> = Reverse(Sort(<variableName1>, Comp));
var <variableName2> = "";
for (var i in <variableName1>) {
if (<variableName2> == "") {
<variableName2> = Replace(Replace(Replace(<variableName1>[i], '["', ""), '",', ": "), ']', "");
} else {
<variableName2> += TextFormatting.NewLine + Replace(Replace(Replace(<variableName1>[i], '["', ""), '",', ": "), ']', "");
}
}
return <variableName2>;
The code block below is an example of the full working expression.
function Comp (a, b) {
When(
IsEmpty(a[1]), -1,
IsEmpty(b[1]), 1,
Iif(a[1]>b[1], 1, -1)
);
};
var arr = [
["BREASTCANCER", $feature.BREASTCANCER],
["CARDIOVASCULAR", $feature.CARDIOVASCULAR],
["CERVICALCANCER", $feature.CERVICALCANCER],
["COLONCANCER", $feature.COLONCANCER],
["DIABETES", $feature.DIABETES],
["INFLUENZA", $feature.INFLUENZA],
["LUNGCANCER", $feature.LUNGCANCER],
["PROSTATECANCER", $feature.PROSTATECANCER],
["SKINCANCER", $feature.SKINCANCER],
];
arr = Reverse(Sort(arr, Comp));
var result = "";
for (var i in arr) {
if (result == "") {
result = Replace(Replace(Replace(arr[i], '["', ""), '",', ": "), ']', "");
} else {
result += TextFormatting.NewLine + Replace(Replace(Replace(arr[i], '["', ""), '",', ": "), ']', "");
}
}
return result;


next to the expression field to a new position under the Select fields section.The image below shows the newly added Diseases-Sorted field with multiple field names and values sorted in a descending order in the pop-up after using the Arcade expression.

Article ID: 000029130
Get help from ArcGIS experts
Start chatting now