Select to view content in your preferred language

Create An Indicator To Sum Unique Records From The Fields Of Two Different Feature Classes

483
2
08-28-2024 05:17 PM
imfnet
by
New Contributor

Aloha,

I think this topic has lightly been discussed before, however I have been running into issues with trying to create an expression that will pull data from two different features and output the sum of that data. Based on the code example below (paths and IDs have been removed for privacy), the error I receive is "Execution Error: Unsupported RHS for IS".

Also attached was the original reference post I used to initially create the expression.

 

Any help would be greatly appreciated. 

Mahalo,

Derek Salinas

 

 

var sql = 'status IS R OR status IS A OR status IS C'

var portal = Portal('Enterprise Portal Directory Here')


//Create a feature set for each point, line, and polygon layer and include the cost feild
var point_fs = FeatureSetByPortalItem(portal, 'ITEM ID HERE', 17, ['status'], false)
var sum_point = Sum(Filter(point_fs, sql), 'status')
var line_fs = FeatureSetByPortalItem(portal, 'ITEM ID HERE', 15, ['status'], false)
var sum_point = Sum(Filter(line_fs, sql), 'status')

//Create an empty array and variable for the new FeatureSet that you will push/combine your features into
var features = [];
var feat;

//Push each feature from each layer into the empty array
for (var f in point_fs) {
    feat = {
        'attributes': {
            'status': f['status']
        }
    };
    Push(features, feat)
}

for (var f in line_fs) {
    feat = {
        'attributes': {
            'status': f['status']
        }
    };
    Push(features, feat)
}

//Create final FeatureSet from combined features
var combinedDict = {
    'fields': [
        { 'name': 'status', 'type': 'esriFieldTypestring' },
    ],
    'geometryType': '',
    'features': features,
};

return FeatureSet(Text(combinedDict));

 

 

 

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

Your sql statement is incorrect. You have to use "=" instead if "IS". You need quotes around the values and sql is picky about the type of quotes. Double quotes are used around the entire statement and single quotes are used for the attributes.

var sql = "status = 'R' OR status = 'A' OR status = 'C'"

You can make this simpler by using IN keyword

var sql = 'status IN ('R', 'A', 'C')"

 

0 Kudos
JenniferAcunto
Esri Regular Contributor

You do not need to use a data expression to sum data from 2 different layers. Pick one layer for the data source and add any desired filters. Add the second layer as a reference layer and add any desired filters. Use Advanced Formatting to add the reference value to the data value. You can find a detailed walkthrough outlined in the first example of this blog: Dashboards That Pop Indicator Hacks

- Jen
0 Kudos