Arcade in Dashboards

912
9
Jump to solution
06-17-2021 09:05 AM
Labels (1)
aroininen
New Contributor III

Hello there!

is it possible to display an arcade expression like the example below in one of the ArcOnline Dashboard items?  Indicator , Items , Details or Rich Text?

basically I would like to display summarized data on a dashboard - charts and graphs work but not ideal - just want to display the values

 

var sql = "ServiceAre_1 IN (2,5,6,8,9)";
var fs = Filter ($layer,sql);

 

var CanC = sum(fs, "F_CanConne_1");
var Reserved = sum(fs, "F_Reserved_1");
var DeswPro = sum(fs, "F_Des_Wpro_1");
var Total = Canc + Reserved + DeswPro;

var result = "CanConnect: " + CanC;
result += TextFormatting.NewLine + "Reserved: " + Reserved;
result += TextFormatting.NewLine + "DeswPro: " + DeswPro;
result += TextFormatting.NewLine + "Total: " + Total;

return result;

Result:

CanConnect: 317

Reserved: 27

DeswPro: 0

Total: 344

end result something like this?

aroininen_0-1623945938521.png

 

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

I guess you'd use the indicator, but to be honest it's something I would trial and error myself.

You should also understand that the data expression is not simple without prior knowledge of how it works, I'd recommend fully reading the documentation and code samples on how to construct the return featureSet (the data expression only returns a featureSet, not a value or string etc.)

The simplest way I can think of getting your itemID is to co to your content page, click on your hosted feature layer and you will see the itemID in the url.

var fsbpi = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'ItemIDd10b9e8dbd7f4cccbd0a938a06c586e9' , 0, ['field or list of fields'], false)
var sql = "ServiceAre_1 IN (2,5,6,8,9)";
var fs = Filter (fsbpi,sql);

 
var CanC = sum(fs, "F_CanConne_1");
var Reserved = sum(fs, "F_Reserved_1");
var DeswPro = sum(fs, "F_Des_Wpro_1");
var Total = Canc + Reserved + DeswPro;

//then construct a new featureSet from CanC, Reserved....

 

 

 

 

View solution in original post

0 Kudos
9 Replies
DavidPike
MVP Frequent Contributor
0 Kudos
aroininen
New Contributor III

great resource - thanks! now I know where to add

I confused on how to reference the layer?

I get this error when using the expression above (which I took from a popup

Execution Error:Runtime Error: Identifier Not Found. $layer

Thanks

Aaron

 

I

0 Kudos
DavidPike
MVP Frequent Contributor

The great thing about the data expression is that it doesn't need to reference a Webmap etc. You first reference content by itemid as a featureSet.

var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'ItemIDd10b9e8dbd7f4cccbd0a938a06c586e9' , 0, ['field or list of fields'], false)
aroininen
New Contributor III

thankyou so much for your help - still cannot get it to work,

for some reason when I click the Globals tab it is empty is that normal?

where do I get the Item ID?

Does the 'feature by portal item' command replace my var fs = Filter ($layer,sql); ? 

Is there a particular item I should be using this expression that summarizes data? List, Indicator, Details?

thanks again

0 Kudos
DavidPike
MVP Frequent Contributor

I guess you'd use the indicator, but to be honest it's something I would trial and error myself.

You should also understand that the data expression is not simple without prior knowledge of how it works, I'd recommend fully reading the documentation and code samples on how to construct the return featureSet (the data expression only returns a featureSet, not a value or string etc.)

The simplest way I can think of getting your itemID is to co to your content page, click on your hosted feature layer and you will see the itemID in the url.

var fsbpi = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'ItemIDd10b9e8dbd7f4cccbd0a938a06c586e9' , 0, ['field or list of fields'], false)
var sql = "ServiceAre_1 IN (2,5,6,8,9)";
var fs = Filter (fsbpi,sql);

 
var CanC = sum(fs, "F_CanConne_1");
var Reserved = sum(fs, "F_Reserved_1");
var DeswPro = sum(fs, "F_Des_Wpro_1");
var Total = Canc + Reserved + DeswPro;

//then construct a new featureSet from CanC, Reserved....

 

 

 

 

0 Kudos
aroininen
New Contributor III

thanks for your help - I will continue reading on returning feature sets - I thought because I had a expression that worked in a pop up it would work in a dashboard too!

I simplified it but still no results

var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com/'), 'f7cb22d41a1d41c69030ad4d6365ceba' , 0, ['F_CanConne_1','F_Reserved_1','F_Des_Wpro_1','ServiceAre_1'], false)

return GroupBy(fs, ['ServiceAre_1'],
[{name: 'total units', expression: 'F_CanConne_1', statistic: 'SUM' },
{name: 'total units', expression: 'F_Reserved_1', statistic: 'SUM' },
{name: 'Total units', expression: 'F_Des_Wpro_1', statistic: 'SUM' }]);

Execution Error:Feature layer must be created with either a url or a source

thanks again I will keep on reading

Cheers

 

 

 

0 Kudos
DavidPike
MVP Frequent Contributor

I'd comment everything out except the first var fs = line, and then build from there.  It looks like a featureSet can't be created from that itemID right at the start, are you entirely sure that's the itemID of the hosted feature layer?  Is it public for me to test?

0 Kudos
aroininen
New Contributor III

hello,

ya when I comment everything out it appears to find the dataset....

is there a way that I can direct send you the link - it not 100% public!

thanks

0 Kudos
ClaudiaGIS
New Contributor III

Hello, I created an expression using Arcade to intersect 2 layers and then show the value in a pop-up. Is there a way to use the same expression in a dashboard? I want to show the value in a list along with other values from the table. Thanks.

0 Kudos