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...):
You're loading the FeatureSets without their geometry. Use this syntax instead (removing the "false" at the end)
FeaturesetByPortalItem(p, "c756ab8f4b654789812c1b9d6d783640", 31, ["*"]),
@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 )
}
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?
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?
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)
}
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.