Dashboard Standard Deviation in Indicator

265
2
04-04-2024 12:05 PM
AdamHart1
New Contributor III

I have a dashboard with some indicators that I would like to show the average and standard deviations of values. The attached picture probably explains it better, but I would like to have the middle indicator have the average value. In the next two indicators to the right, I would like to show the average plus 1 standard deviation, and the next one to the right would be 2 standard deviations above the average. The ones to the left would be 1 and 2 standard deviations below the average. I just can't figure out the right combination of settings and/or Arcade expression to accomplish this. Any help would be appreciated. Thanks

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

I think Arcade is the route to take on this. I don't think we can make it dynamic, if that matters. Arcade has a function built in for standard deviation, but requires your values to be in an array, not a FeatureSet.
To make things easier on your dashboard, we can calculate all 4 things in one go.

var fs = FeatureSetByPortalItem(
Portal('your portal URL'),
'itemid of layer',
0, // layer index
['fields', 'you', 'need'],
false
)

// value array
var numbers = []

for (var f in fs) {
Push(numbers, f['field_you_are_calculating_stdev_for'])
}

// get standard deviation
var sdev = Stdev(numbers)

// mean
var mean = Average(numbers)

// output dict for indicators
var out_dict = {
fields: [
{name: 'stat', type: 'esriFieldTypeString'},
{name: 'value', type: 'esriFieldTypeDouble'}
],
geometryType: '',
features: [
{attributes: {stat: 'pos_one_stdev', value: mean + sdev}},
{attributes: {stat: 'pos_two_stdev', value: mean + (sdev * 2)}},
{attributes: {stat: 'neg_one_stdev', value: mean - sdev}},
{attributes: {stat: 'neg_two_stdev', value: mean - (sdev * 2)}}
]
}

return FeatureSet(Text(out_dict))

Once you've got that, you'll end up with a four-row FeatureSet with your values. Just set those indicators to Feature and filter each so that the relevant statistic is shown.

Apologies for the lack of formatting in the post. The site keeps insisting that there is invalid HTML in my post.

- Josh Carlson
Kendall County GIS
0 Kudos
AdamHart1
New Contributor III

@jcarlson thanks for your reply. Your code does seem promising. However, I do have category selectors that update the map, and I would like the indicators to update as well. So I don't think this would work for my purposes. If it can be done, then I am hoping something similar would work for other statistics like in the attached screenshot. I am also trying to figure out if these stats can be shown in Insights, so I will probably post on that Community as well. Thanks again

0 Kudos