Select to view content in your preferred language

Add Space Between Combined Fields in Field Calculator

14937
34
Jump to solution
05-07-2018 07:30 AM
JRAdams
Regular Contributor

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. 

Thank you!!! AGOL Admin fieldcalculator #arcgisonline

34 Replies
JimmyKroon
Frequent Contributor

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.

JoeBorgione
MVP Emeritus

Thanks Jimmy, I tried the nested approach and it got real ugly after two fields. I tried the + operator as well but that heads south too...

That should just about do it....
0 Kudos
Katie_Clark
MVP Regular Contributor

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.  

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
AlexanderSymonds
Emerging Contributor

THIS WORKED 🙂

0 Kudos
TanyaWinemiller
Emerging Contributor

This one worked for me! Thank you!

0 Kudos
JRAdams
Regular Contributor

I was trying to run as a field calc. Doesn't the Arcade only work on labeling or pop-ups (maybe symbology too?) 

0 Kudos
JoeBorgione
MVP Emeritus

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....)

That should just about do it....
TanyaWinemiller
Emerging Contributor

Yes! This worked perfectly.  Thank you!

 

0 Kudos
KellyGerrow
Esri Alum

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

https://www.arcgis.com/home/webmap/viewer.html?webmap=1267db066ab144e086f84801f5022ef6 

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.

Steps:

   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.

Steps:

   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.

JoeBorgione
MVP Emeritus

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'

That should just about do it....
0 Kudos