PROBLEM
In ArcGIS Dashboards, numeric values that are populated through advanced formatting expressions cannot be sorted in ascending or descending order when the Table elements 'Sort by' option is used.
The Table elements below show the order of the populated field values remains unchanged when 'Sort ascending' or 'Sort descending' is selected.


Table sorting in Dashboards is applied to the underlying FeatureSet before any advanced formatting is evaluated, whereas Arcade expressions only control the 'displayText' property displayed in each table cell during rendering. They do not create, modify, or retain field values in the FeatureSet. Because these calculated values only exist in the visualization layer and are not part of the data used for sorting, the table order remains unchanged when sorting is applied. Sorting is only supported for fields that exist as actual attributes in the FeatureSet before rendering.

Note: The expression below is used to populate the field by combining the values from two other fields. Modify the operations accordingly.
var portal = Portal("portal_URL"); // Replace with URL of the portal
// Get the source FeatureSet
var fs = FeatureSetByPortalItem(
portal,
"ITEM_ID", // Portal item ID of the layer or table
0, // Layer index
[
"CategoryField",
"LabelField",
"NumericField1",
"NumericField2"
],
false
);
// Build a new FeatureSet with calculated values
var features = [];
for (var f in fs) {
var value1 = DefaultValue(f.NumericField1, 0);
var value2 = DefaultValue(f.NumericField2, 0);
Push(features, {
attributes: {
CategoryField: f.CategoryField,
LabelField: f.LabelField,
NumericField1: value1,
NumericField2: value2,
CalculatedField: value1 + value2
}
});
}
// Return the FeatureSet used by the table
return FeatureSet({
fields: [
{ name: "CategoryField", type: "esriFieldTypeString" },
{ name: "LabelField", type: "esriFieldTypeString" },
{ name: "NumericField1", type: "esriFieldTypeInteger" },
{ name: "NumericField2", type: "esriFieldTypeInteger" },
{ name: "CalculatedField", type: "esriFieldTypeInteger" }
],
geometryType: "",
features: features
});
Below is the working script for this example. The NewField field is populated by adding the values in the SalesVolume and EmployeeCount fields.
var portal = Portal("portal_URL"); // Replace with URL of the portal
var fs = FeatureSetByPortalItem(
portal,
"ITEM_ID", // Replace with layer/table ID
0,
[
"Status",
"City",
"SalesVolume",
"EmployeeCount"
],
false
);
var features = [];
for (var f in fs) {
var sales = DefaultValue(f.SalesVolume, 0);
var employees = DefaultValue(f.EmployeeCount, 0);
Push(features, {
attributes: {
Status: f.Status,
City: f.City,
SalesVolume: sales,
EmployeeCount: employees,
NewField: sales + employees
}
});
}
return FeatureSet({
fields: [
{ name: "Status", type: "esriFieldTypeString" },
{ name: "City", type: "esriFieldTypeString" },
{ name: "SalesVolume", type: "esriFieldTypeInteger" },
{ name: "EmployeeCount", type: "esriFieldTypeInteger" },
{ name: "NewField", type: "esriFieldTypeInteger" }
],
geometryType: "",
features: features
});

Note: Delete the old table element from the options menu, if necessary. Refer to ArcGIS Dashboards: Add elements for more information.

$feature.SalesVolume + $feature.EmployeeCount


The Table elements below show the field sorted in the intended order when 'Sort ascending' or 'Sort descending' is selected.


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