Select to view content in your preferred language

Category selector not working on table created from multiple layers through data expression

580
5
02-06-2026 11:49 AM
JohnsonMichelle
Occasional Contributor

Hello, I am very new to dashboards and building data expressions in dashboards.

I have created a data expression to combine multiple layers with identical fields into a single table. However, the category selector I have set up will not work on this table, since it is using a spatial filter.

How can I retain geography for my table, so that it can be filtered spatially?

Thank you for any suggestions!

Here is the data expression I have created to generate my table, built using this post (https://community.esri.com/t5/arcgis-dashboards-questions/create-a-serial-chart-in-a-dashboard-refer...):

 
// load your layers
var p = Portal("https://www.arcgis.com")
var featuresets = [
  FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 31, ["*"], false),
  FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 28, ["*"], false),
  FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 34, ["*"], false),
  FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 35, ["*"], false),
  FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 27, ["*"], false),
  FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 37, ["*"], false),
  FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 30, ["*"], false),
  FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 38, ["*"], false),
  FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 32, ["*"], false),
]

// create the output featureset (this assumes that all layers have the same fields)
var merged_fs = {
  geometryType: 'esriGeometryPoint',
  spatialReference: { wkid: 4269 },  // WGS84
  fields: Schema(featuresets[0]).fields,
  features: []
}

// append every feature of every input layer to the output featureset
for(var fs in featuresets) {
  for(var f in featuresets[fs]) {
    var att = Dictionary(f).attributes
    Push(merged_fs.features, {attributes: att})
    }
}

// and return that featureset
return Featureset(merged_fs)

 

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

You're loading the FeatureSets without their geometry. Use this syntax instead (removing the "false" at the end)

FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 31, ["*"]),

 

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

@KenBuja answer would resolve your issue. Just make that slight change and it should work.

Another thing you can do so that your not needing to update multiple feature changes is to simply create an array of all of the sublayer ids/numbrer and loop through each one and push a new array with the featureset defaults

Ex:

var idarray = [27,28,30,31,32,34,35,37,38]

var fsarray = []

for( var i in idarray ){

    var id = idarray[i]

    var nfs = FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", id )

    Push( fsarray, nfs )

    }

JohnsonMichelle
Occasional Contributor

Thank you both for these suggestions!

I have enabled @KenBuja's solution, but it still does not allow me to use a Category Selector to filter spatially.

Below is an image showing a couple of options I have for applying a category selector - to this combined table (Combined Assets), where I can only filter by fields and to a table directly from something on the map (DEC Conservation Easement Acreages) where I can filter by fields and by a spatial option. I was hoping to have this spatial option available for the combined table. Is it even possible, or do I still need adjustments to my code?

 

 

JohnsonMichelle_0-1770652194514.png

As an alternate option, should I just add an attribute for my category selector as a field to my Combined Assets table (created from the code above) so that I can filter by field instead?

 

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

In this case then you wouldn't need multiple datasets but rather a single featureset to return a basic table of values to filter by. You would need to construct a basic featureset, like the example below, so that it only returns a single table of records. This will require fields to be manually specified for the new featureset table, and the attributes must map accordingly.

function SetFields(N,T,L){
    var b = 'esriFieldType'; var types = ['Integer','Double','String','Date']
    var V = When(
        Includes(types,T) && T=='String',{name:N,type:b+T,'length':L}
        ,Includes(types,T) && T!='String',{name:N,type:b+T}
        ,Null
        )
    return V
    }

var Fields = [
    SetFields('ExampleA','String',25)
    ,SetFields('ExampleB','Integer',Null)
    ]
var Values = []
for( var row in somefeature ){
    var attvals = {'ExampleA':'Something','ExampleB':1}
    Push(Values,{attributes:attvals}
    }
var FS = FeatureSet(Text({
        'fields': Flds
        ,'geometryType': ''
        ,'features': Values
        }))
return FS

@KenBuja might be able to add to this in case I left something out. If you need to add a spatial component then you would simply need to pull that once. The configuration to add a spatial component has a similar structure but requires other spatial information to be returned.

Here is a simple function for simply creating a union of multiple features, assuming they are the same geometry.

function GetFSGeoms(InFS){
    var Poly = []
    for (var f in InFS) { var e=Geometry(f) ; if(!IsEmpty(e)){ Push(Poly,e) } }
    iif(Count(Poly)>0,Union(Poly),Null)
    }
JohnsonMichelle
Occasional Contributor

Thank you! I haven't been able to turn back to this project yet, but this gives me the next step to try. Much appreciated.

0 Kudos