In the ArcGIS Online field calculator I am trying to combine a few other fields into one (address field) and cannot figure out how to put a space between the fields. I am sure it is something simple, but I am unable to find the answer elsewhere. Please help! I've tried everything I can think of.
Solved! Go to Solution.
Pretty sure Kelly's suggestion is an Arcade expression not a field calculator expression. The ArcGIS help has a nesting example to concatenate three strings.
CONCAT('A', CONCAT(':', 'B'))
—result is 'A:B'
Pretty cumbersome for a lot of fields. An Arcade expression would be much better.
You can also concatenate multiple fields in field calculator using +, but for me it works fine with only fields, or only strings, but not trying to concatenate fields and strings together. Weird.
Joe Borgione Kelly Gerrow After reading through several internet resources on SQL syntax and this entire thread, I found that the nested syntax finally worked. All I wanted to do was the very simple task like the OP, to calculate a new field by combining strings from two other fields, separated by a space.
This is the expression that finally worked for me: CONCAT('code', CONCAT(' ', 'desc1'))
Where code and desc1 are both field names that contain strings.
As someone who is working very hard to learn Python as well as keeping track of SQL vs Arcade syntax, I find it fairly confusing and frustrating to constantly be switching between these different languages for expressions. Between ArcMap vs. ArcGIS Online, labels vs. field calculator, etc it seems that there is no consistency. Is there a reason why there needs to be such variation in languages used for expressions? Would it be possible to use Arcade or Python to calculate fields in ArcGIS Online (considering you use Python to calculate fields in ArcMap), or is there a reason it has to be SQL for ArcGIS Online?
Anyway, thanks for listening.
I was able to use Arcade on my test hosted feature with ArcGIS Pro. (Seems kind of lame that you can't do it right there in the AGOL calculator....)
$feature.STREAM+' '+$feature.STREAM+' '+$feature.STREAM
returned the value of the STREAM field with a space between each one....
My guess is you can do the same thing with address components like this:
$feature.HouseNumber+' '+$feature.StreetName+' '+$feature.City+' '+$feature.Zip
(whatever your field names are....)
Two methods of concatenating 3 variables with a space in this post. I'm going to summarize both methods so the solution is clear. For this example feel free to use the layer mentioned below. I have left it editable, so that you can test out the differences of the two methods . Using Arcade is the most straight forward and flexible depending on how you plan to use the created field.
Example Web Map and layer
Create an Arcade expression for displaying in pop ups (or labels or symbology). Arcade can be used to display formatted data as a new field in pop ups or for symbology. If you are using Arcade, any updates to existing data will be displayed in the expression as the expression is created at the time of the pop up to display up to date values.
1. Add layer to Web Map: https://www.arcgis.com/home/item.html?id=7810a6a9ccd0406fb3b7ce7f10aac818
2. Configure Pop Up > Add Attribute Expression
3. Add Expression: Concatenate([$feature.dog1,$feature.dog2,$feature.dog3], ' ')
4. Ensure the created expression is checked to display in pop up (all dogs in this example)
Note: If you want to use this expression as a label or for symbolization, Click New Expression and then select the existing expression to use in web map
Calculate a field value in a table. You can calculate a concatenated field using the calculate field to. This is great for one time changes to data sets. The data will be updated at the time of the calculation and then may need to be updated manually or by calculation if the contributing fields were to change.
1. Display data table in Map Viewer or on Data tab of item details page.
2. Add a field to the table (Calculated Field)
3. Ensure the Field is displaying in the table and select calculate
4. Enter the following calculation:
CONCAT(dog1,CONCAT(' ', CONCAT(dog2,CONCAT(' ',dog3 ))))
5. Verify that the calculated field displays correctly.
I got that to work in the data tab view. But, I can't seem to apply a calculation to a selected field in AGOL. Everytime I use the calculator it is applied to all fields, not just the selected one....
(first row selected, right?
results with all fields now valued with 'joe'
How can I do leading spaces? It keeps striping them out when using Arcade in a Pop up.
return "\n" + " Line Number Issue! Found: " + txt
Does this - notice no spaces - I want to indent it.
\a is the bell, so try it with your speakers off, \n and \t are considered whitespace. So it python-esque principles are followed, you can always find something that doesn't print, but isn't considered whitespace
a = "\n\t\a Line Number Issue! Found: "
Line Number Issue! Found: