I'm seeking assistance with an arcade expression to show some data in a dashboard: Percent from two values in one field of a table to display in an indicator (matched / total).
If I could figure out how to do this without an expression I would be happy, but I don't think the indicator element is capable of calculating a percent.
var fs = FeatureSetByPortalItem(Portal('https://gisportal.company.com/portal'),
'itemId',
0,
[
'matched', //field name
],
false
);
// Count of 'matched' by counting number of rows that are 'matched' and this one is giving me the execution error so can't even get to the next variable
var matched = Count(fs["matched"] == 'matched', 1, null);
// Total count of 'matched' and 'asset only', (this could be totally wrong)
var total = Count((When(fs["matched"] == 'matched', 1, null)) + (When(fs["matched"] == 'asset only', 1, null)));
var percentMatched = (matched / total) * 100;
return FeatureSet(percentMatched);
If it matters/helps, the 'matched' field has three values: matched, asset only, gis only.
Thanks
Solved! Go to Solution.
You don't need to use a data expression for this. Just add your data to an indicator and filter it to provide your 'matched' value. Then toggle on the reference option and add your data without a filter to display the 'total' value.
Then on the Indicator tab, remove the {value} and {reference} fields and use the {} button to select {percentage}.
Thank you so much! I am going to try this now.
You have to return the value in a FeatureSet like this
return FeatureSet(Text({
fields: [{name: 'the_percentage', type: 'esriFieldTypeSingle'}],
geometryType: '',
features: [{attributes:{the_percentage:percentMatched}}]
}))
I was pretty sure about the FeatureSet() part but getting the info for it was giving me trouble. May be able to do this without an expression based on the other response, so I'm going with it for now. Thanks!
You don't need to use a data expression for this. Just add your data to an indicator and filter it to provide your 'matched' value. Then toggle on the reference option and add your data without a filter to display the 'total' value.
Then on the Indicator tab, remove the {value} and {reference} fields and use the {} button to select {percentage}.
Thank you so much! I am going to try this now.