Hello, I am trying to get the following rule to work. I have 3 fields that I would like to get the average from, but in some instances not all 3 fields have values and are null. I would like to average the non null values. I have tried Count, and other varies methods but cant seem to get it to work. Any help would be appreciated. Thanks
VAR LC1 = $feature.Lot_Cost
VAR LC2 = $feature.Lot_Cost_
VAR LC3 = $feature.Lot_Cost__
VAR AVLOT = COUNT([LC1,LC2,LC3])
SUM(LC1,LC2,LC3) / AVLOT
The above is what I am working on, but returns the wrong value.
Solved! Go to Solution.
This is my biggest gripe with Arcade: it treats null values as zero. To circumvent that, you have to manually check each value for null, for example like this:
var values = [$feature.Lot_Cost,
$feature.Lot_Cost_,
$feature.Lot_Cost__,
]
var value_sum = 0
var value_count = 0
for(var i in values) {
if(values[i] != null) {
value_sum += values[i]
value_count ++
}
}
return value_sum / value_count
Related idea (though I don't think this will be implemented): Arcade: Don't treat null as zero in mathematical f... - Esri Community
This is my biggest gripe with Arcade: it treats null values as zero. To circumvent that, you have to manually check each value for null, for example like this:
var values = [$feature.Lot_Cost,
$feature.Lot_Cost_,
$feature.Lot_Cost__,
]
var value_sum = 0
var value_count = 0
for(var i in values) {
if(values[i] != null) {
value_sum += values[i]
value_count ++
}
}
return value_sum / value_count
Related idea (though I don't think this will be implemented): Arcade: Don't treat null as zero in mathematical f... - Esri Community
This is perfect. Thanks again
The immediate workaround to this that comes to mind would be to add a string of code to select all values that are "not null" from the desired feature classes and then passing those selected values to your new variables for calculation. Best of luck!
Derek Wood Pasco County Public Works