Convert text to numbers with ArcGIS Arcade

You have a dataset of property assessment values in the town of Portage la Prairie, in Manitoba, Canada. You want to visualize these values on a map in ArcGIS Online , but at first it seems as though you can't, since they are formatted as text instead of numbers. In this tutorial, you'll learn how to build an expression with ArcGIS Arcade to convert numbers stored as text to true numeric values.

This tutorial was last tested on August 15, 2024.

Requirements

Outline

Convert text to numbers with ArcGIS Arcade

Video

This tutorial is also available as a video.

Play Video

Try to style the map with the Total Value field

You'll start by viewing the property assessment data on a map and reviewing the Total Value field. You'll attempt to symbolize the map with this field.

  1. Open the Portage la Prairie property assessment layer in Map Viewer .

Map of property boundaries in Portage la Prairie, Manitoba, Canada

A map of the town's property boundaries appears.

Note:
If you don't have an organizational account, see options for software access.

Options button and Show table option

The layer's attribute table appears below the map.

Total Value field in the table

You'll visualize this field on the map so you can see which properties have higher values than others.

Styles button

Note:

If the Settings toolbar is unavailable, in the Layers pane, click Portage la Prairie property assessment . The Settings toolbar is only available when a layer is selected.

Field button

The Styles pane updates to show styles that are available for the Total Value field. There are only two: Types (unique symbols) and Location (single symbol) . You hoped to use a quantitative style such as Counts and Amounts (size) , but none are available. Available stylesNear the top of the Styles pane, next to Total Value , the field's type is listed as abc , indicating that it is a string, or text field. Field type indicatorNumeric values are required to use the Counts and Amounts style. It won't work with text values.

Build an Arcade expression

You can still symbolize the map with the Total Value field and the Counts and Amounts style. You will use an Arcade expression to convert the text values into numeric values.

  1. In the Styles pane, next to Total Value , click the Remove button.

Remove field button

The expression builder window appears.

Expand toolbar button

Functions button in the toolbar

The Functions pane appears, listing all the available Arcade functions.

Number functionThe function appears in the expression builder. The value_ parameter is highlighted. Next, you'll replace it with the Total Value field, so leave the parameter highlighted. Number function with highlighted text

Profile variables are data variables from the map that you can use as inputs in your Arcade expression. They include all of the fields from the layer. In the Profile variables pane, $feature refers to the features in the layer. In this case, the features are properties in the Portage la Prairie property assessment layer.

Arrow button next to $feature

A list of all of the fields from the Portage la Prairie property assessment layer appears.

$feature.Total_Value

The expression updates to Number ($feature.Total_Value) . The first parameter, value , is now defined as $feature.Total_Value . The expression will access the Total Value attribute from each feature in the layer. The next parameter, pattern , is optional, so you'll run the expression to test if it works without defining a pattern.

Run button

In the Output window, the output Number: NaN is reported. NaN stands for Not a Number. In this case, the expression did not work with an undefined pattern.

Edited expression

The # character signifies an optional digit in the Number function. The #.## pattern will convert any amount of digits before the decimal and up to two digits after the decimal. The values in the Total Value field are monetary, so there's a possibility that some may be expressed with up to two decimal places. This pattern will ensure that values with decimal places can be converted.

The Output window still reports Number: NaN . Next, you'll consult the function's documentation to find a solution.

Fix the expression

You recall from the attribute table that each number in the Total Value field was prefaced with a $ character. This is a text character. The expression is failing because it can't convert the $ character into a number. You'll consult the Number function's documentation to see if there's a way to remove the $ character.

  1. On the toolbar, click Functions .
  2. In the search bar, type number .
  3. Next to Number(value, pattern?) -> Number , click the arrow button.

Arrow button next to Number function

The function's documentation appears.

Example from the function documentation

The second example shows how to ignore certain characters when converting text to numbers. Number('abc10def', 'abc##def') // return 10 . In the example expression, abc and def are defined as text that should be ignored. You can use this pattern to ignore the $ character.

The final expression should read Number($feature.Total_Value, '$#.##') .

Output

The Output window reports Number: 85200 . The expression was successful in converting values like $85,200 into numbers like 85200.

Note:

If your web browser is set to a language other than American English, the expression may fail due to the commas used as thousands separators. If the Output window still reports Number: NaN , erase the existing expression and replace it with the following:

var numberOnly = Replace($feature.Total_Value, '$', '') // Remove dollar signs. var digitsOnly = Replace(numberOnly, ',', '') // Remove commas. Number(digitsOnly)
Note:
When you click Run , the expression is tested against the first feature in the layer. Now that the expression is complete. you'll change its name to better describe its purpose.

Renamed expression

Map and styles pane

The map reappears. The Styles pane lists the Total Value (numeric) expression as the chosen attribute. Counts and Amounts (color) has been selected as the default style for the numeric values returned by the expression. The map visualizes the values from Total Value field with larger circles for larger assessed property values.

Note:

The Total Value field and the Portage la Prairie property assessment layer are unchanged. The Total Value (numeric) expression is saved in the web map, not in the layer, but if you save a copy of the layer, it will be available for use in other maps.

In this tutorial, you learned how to use the Arcade Number function to convert text values to numeric values for a layer in a map so you could apply the Counts and Amounts style. The expression you wrote— Number($feature.Total_Value, '$#.##') —can also be used to format pop-ups and labels.

You can find more tutorials in the tutorial gallery.

Acknowledgements

Send Us Feedback

Please send us your feedback regarding this tutorial. Tell us what you liked as well as what you didn't. If something in the tutorial didn't work, let us know what it was and where in the tutorial you encountered it (the section name and step number). Use this form to send us feedback.

Share and repurpose this tutorial

Sharing and reusing these tutorials are encouraged. This tutorial is governed by a Creative Commons license (CC BY-SA-NC). See the Terms of Use page for details about adapting this tutorial for your use.