I have a point feature class representing tanks on a site. I want to symbolize the tanks according to the date when last they were filled, which is recorded in a Survey123 form collected by the field workers. I have a table of estimated drop rates (gallons per day) for each tank, so theoretically it's possible to calculate a percentage of how full the tanks are, using the date of last fill, the drop rate, and the tanks' known capacity.
I have code that I think would work, but when writing expressions for symbology the functions FeatureSetbyPortalItem, etc are not allowed. I could put this calculated percentage into the pop-up without issue, but I would really like to symbolize the values on the map if possible.
Is there a workaround that would allow me to symbolize using values pulled from other features?
For reference, here is an expression (pardon my amateur coding) that successfully returns a percentage value which I would like to use for symbology:
//returns a percentage of safe fill capacity based on drop rate
var layerID = $feature.tankID
//query the drop rate table for matching tank ID
var dropRateTable = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'drop rate table portal id');
var filterStatement = "tankID = @layerID"
// must select First record from filtered records, otherwise cannot call values
var tankDropTable = First(filter(dropRateTable, filterStatement))
var tankDropRate = tankDropTable.dropRate
// get date of last fill from form
var formID = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'tank fill form portal id', 1, ['*'], false);
var tank = filter(formID, filterStatement)
if (Count(tank) == 0){
continue
} else {
// Order records by objectid; you can set this to some date field, too
var ordered_tanks = OrderBy(tank, "CreationDate DESC")
var tank = First(ordered_tanks)
var fillDate = tank.CreationDate
}
// calculate days since last fill
var daysSince = Round(DateDiff(Date(), fillDate, 'days'))
// gallons dropped to date
var gallonsDropped = tankDropRate * daysSince
// percent full of safe fill level
var pctFull = Round((($feature.safeFill - gallonsDropped) / $feature.safeFill) * 100)
return pctFull