Expression to count total from multiple layers

510
4
Jump to solution
12-21-2021 02:19 AM
SayedWali
New Contributor III

I want to create an indicator to count items from multiple layers. Is there any arcade expression example or any reference? Any idea will be appreciated.

Tags (2)
1 Solution

Accepted Solutions
jcarlson
MVP Honored Contributor

@SayedWali-  Just to recap and post the solution here, rather than in a private message:

var portal = Portal('https://npaid.maps.arcgis.com');

var FAR = FeatureSetByPortalItem(
    portal,
    '56db417ebbc541bcbb6ccf9c49524cc9',
    0,
    ['*'],
    false
)

var PDIA = FeatureSetByPortalItem(
    portal,
    '56db417ebbc541bcbb6ccf9c49524cc9',
    0,
    ['*'],
    false
)

var total_count = Count(FAR) + Count(PDIA)

var outDict = {
    fields: [{ name: 'total', type: 'esriFieldTypeInteger'}],
    geometryType: '',
    features: [{attributes: {total: total_count}}],
};


// Return dictionary cast as a feature set
return FeatureSet(Text(outDict));

 

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
jcarlson
MVP Honored Contributor

There are a number of examples on ESRI's Arcade expressions GitHub repo. Here's one that counts items from multiple layers for a chart:

https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/CombineMultipleLayers(SerialCh...

If you haven't used a Data Expression before, they can look a lot more complicated than they really are. The linked example should apply just as easily to an Indicator widget.

- Josh Carlson
Kendall County GIS
jcarlson
MVP Honored Contributor

@SayedWali-  Just to recap and post the solution here, rather than in a private message:

var portal = Portal('https://npaid.maps.arcgis.com');

var FAR = FeatureSetByPortalItem(
    portal,
    '56db417ebbc541bcbb6ccf9c49524cc9',
    0,
    ['*'],
    false
)

var PDIA = FeatureSetByPortalItem(
    portal,
    '56db417ebbc541bcbb6ccf9c49524cc9',
    0,
    ['*'],
    false
)

var total_count = Count(FAR) + Count(PDIA)

var outDict = {
    fields: [{ name: 'total', type: 'esriFieldTypeInteger'}],
    geometryType: '',
    features: [{attributes: {total: total_count}}],
};


// Return dictionary cast as a feature set
return FeatureSet(Text(outDict));

 

- Josh Carlson
Kendall County GIS
SayedWali
New Contributor III

Hi @jcarlson , Thank you very much!

SayedWali
New Contributor III

@jcarlson , one more question, from the two layers, I want to get a shared field as a long list. For example, I want to have a list of all object IDs from both layers. any idea to edit the expression?

0 Kudos