Hi,
I'm trying to create an indicator in ArcGIS Dashboards that display the percentage of features with a specific attribute value using an Arcade expression. I can see the correct result in the create new expression window, but once i click "done", the indicator displays: "Unable to execute arcade script"
For context:
var capa = FeatureSetByPortalItem(
Portal(''),
'597723f82afb4031a8211a2a993c7688', // Feature layer ID
0,
['estado']
);
var total = Count(capa);
var rechazadas = Count(Filter(capa, "estado = 'Rechazada IPEEM/Archivo'"));
var porcentaje = IIf(total == 0, 0, Round((rechazadas / total) * 100, 1));
return {
fields: [
{ name: "porcentaje", type: "esriFieldTypeDouble" }
],
geometryType: "",
features: [
{
attributes: {
porcentaje: porcentaje
}
}
]
};
Solved! Go to Solution.
You are returning a Dictionary, not a FeatureSet. You just need to wrap that Dictionary in the FeatureSet function
var capa = FeatureSetByPortalItem(
Portal(""),
"597723f82afb4031a8211a2a993c7688",
0,
["estado"]
);
var total = Count(capa);
var rechazadas = Count(Filter(capa, "estado = 'Rechazada IPEEM/Archivo'"));
var porcentaje = IIf(total == 0, 0, Round(rechazadas / total * 100, 1));
return FeatureSet(
{
fields: [{ name: "porcentaje", type: "esriFieldTypeDouble" }],
geometryType: "",
features: [{ attributes: { porcentaje: porcentaje } }]
}
);
Try something like this, I think you've mostly got it:
// Point to Portal
var p = Portal('https://maps.arcgis.com/')
// Create featureset
var fs = FeatureSetByPortalItem(p, '5c798c532ad5448ea9e973de8ddf8076', 2, ['State'], false)
var total = Count(fs)
var michigan = Count(Filter(fs, "State = 'Michigan'"))
// Calculate percent
var pct = IIf(total == 0, 0, Round((michigan / total) * 100, 1))
// Create dictionary to hold percent calculation
var newDict = {fields: [
{name: 'Percent', type: 'esriFieldTypeDouble'}],
geometryType: '',
features: []
}
// Put percent calculation into dictionary
Push(newDict['features'], {attributes: {Percent: pct}})
// Create a featureset from the dictionary
return FeatureSet(Text(newDict))
You are returning a Dictionary, not a FeatureSet. You just need to wrap that Dictionary in the FeatureSet function
var capa = FeatureSetByPortalItem(
Portal(""),
"597723f82afb4031a8211a2a993c7688",
0,
["estado"]
);
var total = Count(capa);
var rechazadas = Count(Filter(capa, "estado = 'Rechazada IPEEM/Archivo'"));
var porcentaje = IIf(total == 0, 0, Round(rechazadas / total * 100, 1));
return FeatureSet(
{
fields: [{ name: "porcentaje", type: "esriFieldTypeDouble" }],
geometryType: "",
features: [{ attributes: { porcentaje: porcentaje } }]
}
);