Hi everyone,
I'm building an ArcGIS Online Dashboard for dynamic Capital Improvement Project Budget Snapshot, and trying to create a Data Expression using Arcade. I have three tables:
Each table has about 350+ records. Every record represents a monetary value for a project that was created using a joined view between the project layer and it's funding or spending table, summarized as sums (except for Encumbrances, which is a separate table with a single hardlined value), matched across the tables by projectguid.
Goal:
I want to calculate the sum total Available Balance for all projects within an indicator element using the formula:
Available Balance = Appropriations - Encumbrances - Expenditures
Then I will use a List Element in the same dashboard to select the project I want to filter down to, which has a GlobalID that matches the projectguid.
Problem:
My Code:
// Load the tables
var appropriationsTable = FeatureSetByPortalItem(
Portal('https://www.arcgis.com'),
'REDACTED_APPROPRIATIONS_ITEM_ID',
0,
['projectguid', 'fundamount_sum']
);
var encumbrancesTable = FeatureSetByPortalItem(
Portal('https://www.arcgis.com'),
'REDACTED_ENCUMBRANCES_ITEM_ID',
0,
['projectguid', 'Total_Encumbrance']
);
var expendituresTable = FeatureSetByPortalItem(
Portal('https://www.arcgis.com'),
'REDACTED_EXPENDITURES_ITEM_ID',
0,
['projectguid', 'costamount_sum']
);
// Create lookup dictionaries
var encumbranceDict = {};
for (var e in encumbrancesTable) {
encumbranceDict[e.projectguid] = e.Total_Encumbrance;
}
var expenditureDict = {};
for (var exp in expendituresTable) {
expenditureDict[exp.projectguid] = exp.costamount_sum;
}
// Build the new feature set
var features = [];
for (var a in appropriationsTable) {
var projID = a.projectguid;
if (!IsEmpty(projID)) {
var appropriation = DefaultValue(a.fundamount_sum, 0);
var encumbrance = DefaultValue(encumbranceDict[projID], 0);
var expenditure = DefaultValue(expenditureDict[projID], 0);
var availableBalance = (Number(appropriation) - Number(encumbrance) - Number(expenditure));
Push(features, {
attributes: {
projectID: Text(projID),
appropriations: appropriation,
encumbrance: encumbrance,
expenditures: expenditure,
availableBalance: availableBalance
}
});
}
}
// Return final FeatureSet
return {
type: "FeatureSet",
fields: [
{ name: "projectID", type: "esriFieldTypeString" },
{ name: "appropriations", type: "esriFieldTypeDouble" },
{ name: "encumbrance", type: "esriFieldTypeDouble" },
{ name: "expenditures", type: "esriFieldTypeDouble" },
{ name: "availableBalance", type: "esriFieldTypeDouble" }
],
geometryType: "",
features: features
};
What I’ve Checked:
Question:
What else could cause a working Arcade Data Expression to remain grayed out in ArcGIS Dashboards, even after a successful test run?
Are there additional Arcade quirks or hidden Dashboard requirements I might be missing?
Thanks so much for any help or ideas!
Solved! Go to Solution.
In Dashboards, a Data Expression must return a FeatureSet. Your code is returning a dictionary, but that has to be to converted into a FeatureSet for it to be used in the Dashboard.
return FeatureSet({
fields: [
{ name: "projectID", type: "esriFieldTypeString" },
{ name: "appropriations", type: "esriFieldTypeDouble" },
{ name: "encumbrance", type: "esriFieldTypeDouble" },
{ name: "expenditures", type: "esriFieldTypeDouble" },
{ name: "availableBalance", type: "esriFieldTypeDouble" }
],
geometryType: "",
features: features
});
In Dashboards, a Data Expression must return a FeatureSet. Your code is returning a dictionary, but that has to be to converted into a FeatureSet for it to be used in the Dashboard.
return FeatureSet({
fields: [
{ name: "projectID", type: "esriFieldTypeString" },
{ name: "appropriations", type: "esriFieldTypeDouble" },
{ name: "encumbrance", type: "esriFieldTypeDouble" },
{ name: "expenditures", type: "esriFieldTypeDouble" },
{ name: "availableBalance", type: "esriFieldTypeDouble" }
],
geometryType: "",
features: features
});
You're absolutely right. I had thought I had FeatureSet in there and did not. Thank you!