Do you want to know how to concatenate information from two different fields into one label in your map? Or maybe you need to figure out how to have two lines in your label, each line pulling information from a different attribute. Whether you are creating a map in ArcGIS Pro or ArcGIS Online, Arcade expressions can help you customize your labels to look exactly how you want them to.
In this tutorial, you will learn how to use Arcade expressions to accomplish the following:
- Concatenate two fields into a single label.
- Change the format of your number field to alter the way it displays.
- Create two lines for your label.
- Turn your double field into a percentage in your label.
How can I concatenate two fields into a single label?
If you have an attribute table that has two separate fields, it is very easy to use Arcade expressions to concatenate them into a single label. For this example, we are using an attribute table that has a Official Doc ID field and a Deed Type. Right now, they are separate fields, as shown in the attribute table below.
We want our feature label to look like this: Doc #31406 (QC)
From the Label Class pane, we need to first navigate to the Class configuration tab. From there, we need to change the language from Python to Arcade.
From there, we need to enter the below expression and then click on Apply.
“Doc #”+$feature.OfficialDocID+” (“+$feature.DeedType+”)”
Using a combination of direct quotes and text with field values within an Arcade expression, we are able to create a more complex label than what is possible using the available defaults.
How can I create a label with two lines?
But what if we want our Deed type to be on a second line, and not directly after the Doc ID? All we need to do for this is add an additional function to our expression. Go back into your label class configuration pane and add the following function after the first variable: TextFormatting.NewLine
Your expression should look like the below :
“Doc #”+$feature.OfficialDocID+TextFormatting.NewLine+” (“+$feature.DeedType+”)”
Once you hit apply, you will see your Deed Type has been moved below the Doc ID.
How can I control the format of my numbers?
Instead of having the Deed Type on the second line of our label, we now want to show the adjusted sales price of the parcel. We want to include a money symbol, as well as use comma’s to help standardize the numbers and make them easier to for our audience to read.
To do this, we will delete all text and variables after the New Line function and replace it with the following: text($feature.AdjSalesPrice, “$#,###”)
Your expression and labels should now look like the below :
“Doc #”+$feature.OfficialDocID+TextFormatting.NewLine+text($feature.AdjSalesPrice, “$#,###”)
How can I turn my double field into a percentage?
Now we want to add a line that shows the Sales Ratio data from the attribute table, but we want it to show as a percentage rounded to two decimal places. To do this, we will add the TextFormatting.NewLine function in combination with a text function: TextFormatting.NewLine+”Sales Ratio “+text($feature.SalesRatio,”##.##%”)
The new expression should look like the below:
“Doc #”+$feature.OfficialDocID+TextFormatting.NewLine+text($feature.AdjSalesPrice, “$#,###”)+TextFormatting.NewLine+”Sales Ratio “+text($feature.SalesRatio,”##.##%”)