Hello folks,
I am trying to get the total of three fields to display on an Dashboard Indicator , Table or Gauge
the layer where the fields are located is called:
TBM Internal Planning - Sewer Capacity-CWWTP
Looking for the Gauge/ Indicator/ table to show something like this:
CanCoonect 1614
Reserved 3193
DesPro 1679
Total 6486
All would be ideal ... just the total would be fine too..
Here is my expression so far.... any suggestions...? this expression seemed to work in a popup but no luck in dashboard
FYI - I'm pretty new to Arcade -
var Canc = Sum(fs, "S_CanConne_");
var Reserved = Sum(fs, "S_Reserved");
var DeswPro = Sum(fs, "S_DesWpro");
var Total = Canc + Reserved + DeswPro;
// structure the result
var result = "CanConnect: " + CanC;
result += TextFormatting.NewLine + "Reserved: " + Reserved;
result += TextFormatting.NewLine + "DeswPro: " + Deswpro;
result += TextFormatting.NewLine + "Total: " + Total;
// return the result
return result;
First, if you're going to post code, please use the Insert/Edit code sample button. That makes it easier to read the code and copy it to test it.
Second, you haven't created the FeatureSet fs to get your sums.
Third, a data expression has to return a FeatureSet to be used in a indicator, table, or gauge. To show the total of the sums in an indicator, you could use this return (using the rest of your code)
return FeatureSet(
{
fields: [{ alias: "Total", name: "Total", type: "esriFieldTypeInteger" }],
features: [{ attributes: { Total: total } }]
}
);
You could create a table with this return
return FeatureSet(
{
fields: [
{ alias: "Can Connect", name: "CanConnect", type: "esriFieldTypeInteger" },
{ alias: "Reserved", name: "Reserved", type: "esriFieldTypeInteger" },
{ alias: "DeswPro", name: "DeswPro", type: "esriFieldTypeInteger" },
{ alias: "Total", name: "Total", type: "esriFieldTypeInteger" }
],
features: [
{
attributes:
{
CanConnect: CanC,
Reserved: Reserved,
DeswPro: DeswPro,
Total: total
}
}
]
}
);
thanks for quick reply, I update my post re code... thx
just curious where do I add the field names in the code you provided... also how does it know what layer to get fields from...?
You have to specify that using the FeatureSetByPortalItem function.
var fs = FeatureSetByPortalItem(Portal('yourPortalUrl'), 'yourItemId', 0, ['S_CanConne_', 'S_Reserved', 'S_DesWpro'], false);
var Canc = Sum(fs, "S_CanConne_");
var Reserved = Sum(fs, "S_Reserved");
var DeswPro = Sum(fs, "S_DesWpro");
return FeatureSet(
{
fields: [
{ alias: "Can Connect", name: "CanConnect", type: "esriFieldTypeInteger" },
{ alias: "Reserved", name: "Reserved", type: "esriFieldTypeInteger" },
{ alias: "DeswPro", name: "DeswPro", type: "esriFieldTypeInteger" },
{ alias: "Total", name: "Total", type: "esriFieldTypeInteger" }
],
features: [
{
attributes:
{
CanConnect: CanC,
Reserved: Reserved,
DeswPro: DeswPro,
Total: CanC + Reserved + DeswPro
}
}
]
}
);
thanks...again! I added the portal and ID and layer ID but I keep getting this error:
Test execution error: layerId=0 provided for Dashboard item. Verify test data. - it appears this may be a bug?
var fs = FeatureSetByPortalItem(Portal('https://thebluemountains.maps.arcgis.com'), '4a1e7bbdef0045599cbf567451bcd2bf', 0, ['S_CanConne', 'S_Reserved', 'S_Des_Wpro'], false);
var Canc = Sum(fs, "S_CanConne");
var Reserved = Sum(fs, "S_Reserved");
var DeswPro = Sum(fs, "S_Des_Wpro");
return FeatureSet(
{
fields: [
{ alias: "S_CanConne", name: "S_CanConne", type: "esriFieldTypeInteger" },
{ alias: "S_Reserved", name: "S_Reserved", type: "esriFieldTypeInteger" },
{ alias: "S_Des_Wpro", name: "S_Des_Wpro", type: "esriFieldTypeInteger" },
{ alias: "Total", name: "Total", type: "esriFieldTypeInteger" }
],
features: [
{
attributes:
{
S_CanConne: CanC,
S_Reserved: Reserved,
S_Des_Wpro: DeswPro,
Total: CanC + Reserved + DeswPro
}
}
]
}
);
Since this not a public item, I cannot test it. You'd have to check whether the layer you're using from that service is valid. Put your layer information into a url to see if you can open it.
https://thebluemountains.maps.arcgis.com/home/item.html?id=4a1e7bbdef0045599cbf567451bcd2bf&sublayer=0
If that doesn't give you the correct layer, then examine the item's overview page and determine which layer ID you should use.
thank you for your help... I am at a loss
The over page is for the Dashboard:
https://thebluemountains.maps.arcgis.com/home/item.html?id=4a1e7bbdef0045599cbf567451bcd2bf#overview
This is the infromation URL / ID etc from the Webmap used in the dashboard:
https://thebluemountains.maps.arcgis.com/home/item.html?id=4a1e7bbdef0045599cbf567451bcd2bf#overview
This is the url etc from the actual layer
https://gis.thebluemountains.ca/arcgis/rest/services/Organization/TBM_Internal_Planning/MapServer/0
Service Item Id: 2a7e2d06a6b34823baef6a367fea0429
I have tried all of these in the expression but same error - any thoughts..?
Have you tried using 2a7e2d06a6b34823baef6a367fea0429 as the itemId?
I have and I get this error
Test execution error: Unknown Error. Verify test data.
what portal url should I be using?
https://gis.thebluemountains.ca/arcgis is from the layer url
https://thebluemountains.maps.arcgis.com/ this is from the portal home page
var fs = FeatureSetByPortalItem(Portal('https://gis.thebluemountains.ca/arcgis'), '2a7e2d06a6b34823baef6a367fea0429', 0, ['S_CanConne_', 'S_Reserved', 'S_DesWpro'], false);
var Canc = Sum(fs, "S_CanConne");
var Reserved = Sum(fs, "S_Reserved");
var DeswPro = Sum(fs, "S_Des_Wpro");
return FeatureSet(
{
fields: [
{ alias: "Can Connect", name: "CanConnect", type: "esriFieldTypeInteger" },
{ alias: "Reserved", name: "Reserved", type: "esriFieldTypeInteger" },
{ alias: "DeswPro", name: "DeswPro", type: "esriFieldTypeInteger" },
{ alias: "Total", name: "Total", type: "esriFieldTypeInteger" }
],
features: [
{
attributes:
{
CanConnect: CanC,
Reserved: Reserved,
DeswPro: DeswPro,
Total: CanC + Reserved + DeswPro
}
}
]
}
);
Did you try
var fs = FeatureSetByPortalItem(Portal('https://thebluemountains.maps.arcgis.com/'), '2a7e2d06a6b34823baef6a367fea0429', 0, ['S_CanConne_', 'S_Reserved', 'S_DesWpro'], false);