Frequently asked question

Is it possible to perform calculations using values from another feature in the Calculate Field tool?

Last Published: September 14, 2023

Answer

It is possible to perform calculations using values from another feature in the Calculate Field tool in ArcGIS Pro. When running calculations on a field in an attribute table or a standalone table, the ArcGIS Arcade FeatureSetByName() and the FeatureSetByPortalItems() functions allow the retrieval of the values from fields in different tables. Use the FeatureSetByName() function for value retrieval between tables within ArcGIS Pro, and the FeatureSetByPortalItems() function for value retrieval with a connected portal, using either the ArcGIS Online organizational account or Portal for ArcGIS.

Retrieve values from another table or feature within ArcGIS Pro

When using the FeatureSetByName() function, the following parameters must be considered:

  • The location of the data. '$map' if the data is on the map, or '$datastore' if the data is in the same geodatabase.
  • The feature or table name.
  • The field name(s). This parameter is optional. The function retrieves every field available if no field name is provided. This may affect processing time depending on the table size.
  • The geometry Boolean values (True or False). This parameter is optional. Setting the value to 'True' retrieves the feature’s complete geometry details and setting it as False retrieves the value as is. Setting the parameter to 'True' may affect processing time.

The following is what the function looks like:

FeatureSetByName(<data_location>,'<feature_name>', ['<field_name1>', '<field_name2>', ....] <geometry>);

The following is a sample working code to add the first value from another table into the current table the Calculate Field tool is run on:

var tbl = FeatureSetByName($datastore,"house",['Shape_Length'], False);
var feat = First(tbl)
return $feature.Shape_Length + feat.Shape_Length
Script sample for adding values from another feature in ArcGIS Pro

Retrieving values from another table in ArcGIS Online or Portal for ArcGIS.

When using the FeatureSetByPortalItem() function, the following parameters must be considered:

  • The Portal URL. The URL follows the connected portal set in ArcGIS Pro, either with an ArcGIS Online organizational account or a Portal for ArcGIS portal.
  • The item ID of the selected feature or table.
  • The sublayer ID of the selected feature or table.
  • The field name(s). This parameter is optional. The function retrieves every field available if no field name is provided. This may affect processing time depending on the table size.
  • The geometry Boolean values (True or False). This parameter is optional. Setting the value to 'True' retrieves the feature’s complete geometry details and setting it as 'False' retrieves the value just as is. Setting the parameter to 'True' may affect processing time.

The function is displayed as follows:

featureSetByPortalID(Portal(<Portal URL>, "<feature_ID>", "<sublayer_ID>”, ['<field_name1>', '<field_name2>', ...] <geometry>)

The following is a sample working code to count the number of features from another table in ArcGIS Online or Portal for ArcGIS into the current table the Calculate Field tool is run on:

  • In ArcGIS Online
var feat = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'c43e270e9casdfasxcaedc6', 0, ['Direction'], false );

Count(feat);
  • In Portal for ArcGIS
var feat = FeatureSetByPortalItem(Portal(‘https://machine.domain.com/portal'), 'c43awsfvsdrvsaf7a009c27ad38fce96', 1, ['Direction', 'Signs'], false );

Count(feat);
Script sample for adding values from another feature from ArcGIS Online

Article ID:000031106

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Pro 2 9x
  • ArcGIS Enterprise 10 9 x
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1
  • ArcGIS Pro 3 0
  • ArcGIS Pro 3 1

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options