Select to view content in your preferred language

How do I create a permanent field calculation in an AGOL feature layer?

14747
19
02-21-2020 09:15 AM
AshleyThornton
New Contributor

I have create a map to use in Collector for ArcGIS for the fire department. After using it they have a request: Once they input values for Field A and Field B, they want Field C to calculate a solution using Fields A and B.

I have used the calculate field function in AGOL (ex. Field C = Field A + Field B). However, the field will not 'remember' this calculation. I want the field calculation to stay in that field so that each time I or another user opens the map and inputs the data for A and B, it will auto-populate the value for C.  Is there a way to NOT have to run a field calculation each time I open the map?

19 Replies
JoshSender2
Emerging Contributor

It seems like we should be able to accomplish this - making a calculated column usable in a dashboard indicator or list - by writing an advanced formatting arcade expression.  For the life of me though, I cannot seem to figure it out the correct code.  In my head, here's the way it would work

  1. Define a feature set from the existing item (FeatureSetByPortalItem)
  2. Define a new feature set by defining a dictionary which has all the same fields as the original feature set plus the additional yet to be calculated field
  3. Write a for loop that would iterate over the number of features in the original feature set and would assign attribute values to the new feature set - with the values of the not-calculated fields simply being equal to the i(th) [the iteration number] value in the original feature set of the corresponding original attribute, and the calculated column references some combination of the original feature set i(th) attribute values.
  4. Return the new feature set and make a list or indicator from the new values.

Great in theory, but I cannot seem to make it actually work.  This sort of thing is super simple in Power BI - making a calculated column.  But all of the Googling and trying I've done so far say it's either difficult or impossible in ArcGIS Dashboards.

I'm happy to share my nonfunctioning code if anyone thinks they can actually make this work.

Kantoor__DataCount_-_Verkeerso
Occasional Contributor

Same problem here..

0 Kudos
DavidForbuss1
Frequent Contributor

This worked! Thanks @SallyGalewski !  Can't wait to implement this in some of my maps.  The only thing I noticed that didn't seem to work was labeling off of this expression field.  That'd be a nice addition so the field crews see the calc'd value right away.

0 Kudos
davidlam123
New Contributor

Hi, I am also struggling for this question and haven't figured out a solution to fix it.  dashboard doesn't inherit AGOL expression. it doesn't add to the feature layer itself, but only the pop-up. is there any way to fix this issue. I have a lot of calculated field in attribute table. I need the attribute table to automatically calculate and remember the calculated field when i append new row of data. Eventually, the information is captured automatically in dashboard configured list of element

0 Kudos
MattTarkington1
Occasional Contributor

I too have been struggling with this for quite a while and have found a bit of a solution! (if you have access to ArcPro).

I pull my feature layer out of the portal into ArcPro and put the Calculate Field into a Model scheduled to run periodically. 

Only downside I see to this is that the machine with the Scheduled Tool has to be on in order for this to work. As I understand it, ArcPro doesn't even have to be open. 

Screenshot 2021-12-30 175632.jpg

 

Hope this helps!

 

 

0 Kudos
JoshSender2
Emerging Contributor

I just tested this out on some scrap data and this works brilliantly.  It is in no way shape or form the ideal solution to this issue, but hey, any solution is better than no solution.

Thanks for sharing!

timshapiro
Emerging Contributor

would it be possible to do this using Notebooks?

0 Kudos
MattTarkington1
Occasional Contributor

I believe so. It's something that I'm experimenting now. Having issue's with the arcpy.management CalculateField module though.

0 Kudos
MattTarkington1
Occasional Contributor

I have been able to get this to work in notebooks. It runs faster than in a model builder. And you have access to more Python modules.

0 Kudos
DavidForbuss1
Frequent Contributor

I use an acrade script to create a popup that calcs two dates against each other.  Seems like you could do the same for other fields.  I got this template from a forum on  here (sorry, I forgot where or I'd give them credit).  Anyway, here's mine.  Must be used in the new map viewer, so add this as one of your expressions, then in the popup add {expr/1} or whatever number it is:

 

// Access 'Inspections' table as a FeatureSet
var portal = Portal("PORTAL ADDRESS HERE")
var inspections = FeatureSetByPortalItem(portal,
"ITEM NUMBER HERE", <layer # in service here>, ['field1', 'field2',
'field3'])

// Filter related features by using a common attribute
var facilityid = $feature.parentID
var filterStatement = 'childID = @parentID'

// Related features as a variable
var relatedData = Filter(inspections, filterStatement)

// Sort related features by oldest to newest
var relatedDataSorted = Top(OrderBy(relatedData, 'field3 DESC'),1)

// Build the pop-up string by iterating through all related features
var popupString = 'Last Flushed Date: '
for (var f in relatedDataSorted){

popupString += Text(f.field3, 'MM/DD/YYYY')

}

DefaultValue(popupString, 'No measurements to show')

0 Kudos