Hi Gregory Bacon ,
You were close indeed. Only of the problems was looping through a count when that should have been a featureset. You are right about the logic. We start off with a variable sum_dbh which is set to 0 before looping through the features. For each feature the dbh_trunk is added to the running total stored in sum_dbh and that value is returned at the end of the loop.
Regarding performance, both the sum and manually looping through the features could cost the same time as you are experiencing. In theory, it should be less time when less requests are made to the server. This could be done by using a single line:
return Sum(Intersects(FeatureSetByName($map,"Urban Forestry"), $feature), "DBH_TRUNK");
Not sure though if you will notice any difference. Another aspect could be to limit the number of fields returned by the FeatureSetByName:
return Sum(Intersects(FeatureSetByName($map,"Urban Forestry", ["DBH_TRUNK"], False), $feature), "DBH_TRUNK");
(note entirely sure if I use the correct field list)