ArcGIS Online Arcade – Using Arcade Labeling to Sum Area of Attribute for a Project

arcadearcgis-onlinelabeling

I'm struggling to create an expression to sum the total area of a project for a certain attribute. The areas are continuous so I'd like to be able to create a label that had both the features acres and total acres

The data structure is currently: ProjectName, Type, Acreage

The Type is one of two things:

  • Useable
  • Unusable

Screen shot of data

Acreage is labelling expression to convert sq m into acres.

Is there a way that I could get the label to return the Sum of all Useable and Unusable depending on the project?

The desired label would look like:

Project – xxx
Type – Usable rent
Acres – xxx

Total Acres of Usable Rent for Project: xxx
Total Acres of Unusable Rent for Project: xxx

Best Answer

I don't believe what you want is possible when creating a label as the functions that allow you to access and summarize data from an entire layer do not appear to be available when labelling. It seems you are limited to $feature, but you can create the text as a pop-up.

To answer your question I have to spoof up some sample data, this is shown below:

Sample data

You then configure the pop-up and create an expression:

// Get the project, type and acres for feature
var p = $feature["Project"];
var t = $feature["Type"];
var a = $feature["Acres"];

// Create a SQL query to query at a project level for the feature
var q = "Project = '" + p + "'";

// Compute sum area for project/type, this creates a featureset
var fs_stats = GroupBy($layer,['Project','Type'],{name: 'TotalArea', expression: 'Acres', statistic: 'SUM'});

//Create subsets from fs_stats
var fs_Proj = Filter(fs_stats,q); //Creates featureset for just project
var fs_Unused = Filter(fs_Proj,"Type = 'Unuse'"); // A featureset of 1 row
var fs_Used = Filter(fs_Proj,"Type = 'Use'"); // A featureset of 1 row

// Extract out the Total area for the unused type for the project
var TA_Unused = 0;
for(var f in fs_Unused){
 TA_Unused += f["TotalArea"];}

// Extract out the Total area for the used type for the project 
var TA_used = 0;
for(var f in fs_Used){
 TA_used += f["TotalArea"];}

// Create text for pop up
var l = Concatenate(["Project - " , p , TextFormatting.NewLine , "Type - " , t , TextFormatting.NewLine , "Acres - " , a, TextFormatting.NewLine, "Total Acres of Usable Rent for Project:", TA_used,TextFormatting.NewLine,"Total Acres of Unusable Rent for Project: " , TA_Unused]); 

// Return text that becomes the pop-up text
return l

I then assigned this expression to the Title and turned off fields

The final output is:

Pop-up