Convert text to numbers with ArcGIS Arcade
This tutorial is also available as a 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.
- Open the Portage la Prairie property assessment layer in Map Viewer.
A map of the town's property boundaries appears.
- If necessary, on the ribbon, click Sign In and sign in to your ArcGIS organizational account.
If you don't have an organizational account, see options for software access.
- In the Layers pane, on the layer name, click the Options button and click Show table.
The layer's attribute table appears below the map.
- Scroll horizontally through the table to find the Total Value field.
You'll visualize this field on the map so you can see which properties have higher values than others.
- Close the table.
- On the Settings toolbar on the right side of the screen, click the Styles button.
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.
- In the Styles pane, click the Field button.
- In the Add fields window, click Total Value and click Add.
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.
Near 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.
Numeric 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.
- In the Styles pane, next to Total Value, click the Remove button.
- Click the Expression button.
The expression builder window appears.
- Near the bottom of the window, click the Expand button.
- In the expanded toolbar, click Functions.
The Functions pane appears, listing all the available Arcade functions.
- In the search bar, type number.
The list filters to one function, Number(value, pattern?) -> Number.
- Number is the name of the function.
- Value and pattern are its two parameters. The question mark indicates that pattern is an optional parameter.
- The -> Number text at the end indicates that the output of this function will be a number.
You'll use this function to convert the text values stored in the Total Value field into numeric values.
- Click Number(value, pattern?) -> Number.
The 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.
- On the toolbar, click Profile variables.
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.
- Next to $feature, click the arrow button.
A list of all of the fields from the Portage la Prairie property assessment layer appears.
- Scroll to the bottom of the list and click $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.
- Above the expression builder, click Run.
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.
- Edit the expression to Number($feature.Total_Value, '#.##').
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.
- Click Run again.
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.
- On the toolbar, click Functions.
- In the search bar, type number.
- Next to Number(value, pattern?) -> Number, click the arrow button.
The function's documentation appears.
- Scroll down to the Examples section.
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.
- In the expression builder, place your cursor in front of #.## and type $.
The final expression should read Number($feature.Total_Value, '$#.##').
- Click Run.
The Output window reports Number: 85200. The expression was successful in converting values like $85,200 into numbers like 85200.
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)
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.
- At the top of the window, click New expression. Erase the existing text and type Total Value (numeric).
- Click Done.
The map reappears. The Styles pane lists the Total Value (numeric) expression as the chosen attribute. Counts and Amounts (size) 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.
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.