Select to view content in your preferred language

Combing fields to one field for table in Esri Dashboard

923
3
03-30-2022 08:49 AM
anonymous55
Occasional Contributor II

Hello all

I am trying to combine three fields for webservice to one field and show it on table in dashboard. 
I don't know if this is possible or not for now or I can use Arcade for this. I don't want to add field to data.

Tags (3)
0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

This is definitely possible, but you'll need to use a Data Expression. You can see some examples here that may be helpful to you.

Can you elaborate on what these fields look like? When you say "combine", do you mean you want to aggregate the values in some way, or are they just text that you want to merge together?

- Josh Carlson
Kendall County GIS
0 Kudos
anonymous55
Occasional Contributor II

something like this in one fields: 

AidBidCidAid, Bid, Cid
xyzx,y,z
    


all fields are string and in one table. I am using table widget in dashboard

0 Kudos
jcarlson
MVP Esteemed Contributor

Not sure if this will work, but it's a starting point. You basically need to run through your features and concatenate those values for each, then push the features into a new FeatureSet.

// connect to layer
var fs = FeatureSetByPortalItem(
    Portal('your-portal-url'),
    'itemID of your layer',
    0, // or whatever layer index it is
    ['*'], // you can limit the incoming fields to improve perfomance if you like
    false
)

// get schema for layer
var out_fields = Schema(fs)['fields']

// add a new field to the schema to hold "merged" data
Push(
    out_fields,
    {name: 'aidbidcid', alias: 'Aid, Bid, Cid', type: 'esriFieldTypeString'}
)

// Use updated schema to create new dict
var out_dict = {
    fields: out_fields,
    geometryType: '',
    features: []
}

// Iterate over features and concatenate new field, populate output dict
for (var f in fs){
    
    // Create dictionary from existing attributes
    var atts = Dictionary(Text(f))['attributes']
    
    // Array of fields to concatenate
    var ids = [
        f['Aid'],
        f['Bid'],
        f['Cid']
    ]
    
    // add new attribute to dictionary
    atts['aidbidcid'] = Concatentate(ids, ',')
    
    // push feature to output dict
    Push(
        out_dict['features'],
        atts)
    
}

Return FeatureSet(Text(out_dict))

 

- Josh Carlson
Kendall County GIS