Create effective data expressions

Data expressions can be created to power data-driven elements in your dashboard. They allow you to create effective dashboards by building robust visualizations using datasets you have access to. The following are best practices for creating effective data expressions.


You can view sample data expressions to help you get started.

Data expressions have performance tradeoffs and should not be used for complex workflows or large datasets. In these situations, if you are working with data that you own, remodeling and publishing hosted layers is recommended.

  • When querying for a layer's data using FeatureSet functions, request only the features and columns that you need, and query for geometry data only when necessary.

    The following data expression fetches only the required columns and no geometry from the layer by specifying them in the FeatureSetByPortalItem function. The Filter function is then used to return only the rows that are necessary for the visualization.

    var fs = Filter(Portal(''),'f8492125f78445b284751ced4e9d6573',0,['Waterbody_Type', 'Sample_Date', 'Mercury'], geometry = false),'Mercury > 0.3');

  • You can reuse data expressions in multiple elements in the same dashboard. Avoid creating multiple expressions that process and return the same data.
  • Avoid using geometry functions in your data expressions. Geometry functions can impact your dashboard's performance. Instead, process your data in advance.

    The following expression is executing the Contains() and Buffer() geometry methods to find fossil fuel extraction units within 50 miles of national forests. Location information of national forests and extraction units are in two different layers. Since the geometry methods are executed for each national forest in the dataset over a for loop, the expression is slow.

    var p = ''; 
    var nf = '% NF';  
    var nfs = Filter(FeatureSetByPortalItem(Portal(p),'3d86e0ee5f34471ab30a1ad19a08c21f',0),'NAME LIKE @nf');  
    var wells = FeatureSetByPortalItem(Portal(p),'f30ebe47eebc4534b7a385835d6bfedb',0);
    var Dict = {  
     'fields': [{ 'name': 'NF_name', 'type': 'esriFieldTypeString' },  
     {'name': 'area','type': 'esriFieldTypeDouble'},  
     {'name': 'n_wells','type': 'esriFieldTypeInteger'}],  
     'geometryType': '',   
     'features': []};  
    var counts = 0;   
    var index = 0;  
    for (var nf in nfs) {   
        counts = Count(Contains(Buffer(nf, 50, 'miles'), wells))  
        Dict.features[index] = {   
                'attributes': {   
                    'NF_name': nf.NAME,    
                    'area': nf.SQMI,    
                    'n_wells': counts  
        index++; };  
    return FeatureSet(Text(Dict));

  • Avoid using data expressions for operations or queries that can be performed with the standard configuration of dashboard elements.

    For example, any data-driven element can use filters to produce the result of the following expression:

    return Filter(Portal(''),'f8492125f78445b284751ced4e9d6573',0,['Waterbody_Type','Sample_Date','Mercury'], geometry = false),'Mercury > 0.3');

  • Avoid processing large datasets using data expressions.

    The following expression transforms a column's comma-separated values into separate rows. This processing is performed in a for loop, one feature at a time, resulting in a slow expression.

    var fs = FeatureSetByPortalItem(Portal(''), 'd10b9e8dbd7f4cccbd0a938a06c586e9',0,['Report_road_condition'], false);
    var choicesDict =  
    {'fields': [{'name': 'split_choices', 'type': 'esriFieldTypeString'}],  
      'geometryType': '',  
      'features': []};  
    var index = 0;  
    for (var feature in fs) {  
        var split_array  =  Split(feature["Report_road_condition"], ',')  
        var count_arr = Count(split_array)  
        for(var i = 0; i < count_arr; i++){  
            choicesDict.features[index] = {  
                'attributes': {
                } }  
    return GroupBy(FeatureSet(Text(choicesDict)),['split_choices'], [ {name:'split_count',expression:'split_choices',statistic: 'COUNT'}]);

  • Only set refresh intervals on your data expression if the underlying data updates. Set the refresh interval to a value that reflects how often the data is updated.
  • Save copies of your data expressions using a text editor. Unused data expressions in a dashboard are not saved.
  • Data expressions should not be viewed as a replacement for good data modeling. Wherever possible, process your data before bringing it into a dashboard.