Hello,
I have point building data that contains multiple entries for the same facility (points on top of points in the same Feature Layer). The points are created each fiscal year.
I am trying to use Arcade to get the most current Fiscal Year data and populate any popup with the same facility ID.
Here is the code I have come up with:
//Access portal and Get Feature
var portal = Portal("https://*******************.maps.arcgis.com/")
var fac = FeatureSetByPortalItem (portal,"***************************", 0, ['*'],false)
//Filter features by 'FacilityID' when clicking on a feature
var this = $feature.FacilityID
var filterStatement = 'FacilityID =@this'
var allElement = Filter(fac, filterStatement)
//Select most current data
var popupString=''
if (allElement.FiscalYear =='2021-2022'){
popupString += allElement.TotalGHG
}
//format text
var popupStringB = Text (popupString, '###,###.0')
//populate popup
DefaultValue(popupStringB, 'no data')
Any suggestions would be appreciated.
Randy
Solved! Go to Solution.
Sorry about that. There was an extra "=" that I overlooked. Try this
var filterStatement = "FacilityID = @this AND FiscalYear = '2021-2022'";
Since there appears to be only one point per fiscal year, why not add that into your filter? Then you should be able to get the single point.
var filterStatement = "FacilityID = @this AND FiscalYear == '2021-2022'"
Next, the Filter function returns a FeatureSet, so you'll have to get at the data differently. Since you should only have one record here, you can use the First function to get that record.
var allElement = Filter(fac, filterStatement);
var myFeature = First(allElement);
var PopupStringB = Text(myFeature.TotalGHG, '###,###.0')
DefaultValue(popupStringB, 'no data')
Hello KenBuja,
Thank you for taking the time.
I tried your suggestion but get the following result:
The code I used:
//Access portal and Get Feature
var portal = Portal("https://**************.maps.arcgis.com/")
var fac = FeatureSetByPortalItem (portal,"cbf4d4cf514a44b91493d0cb7bb569", 0, ['*'],false)
//Filter features by 'FacilityID' when clicking on a feature
var this = $feature.FacilityID;
var filterStatement = "FacilityID =@this AND FiscalYear =='2021-2022'";
var allElement = Filter(fac, filterStatement);
var myFeature = First(allElement);
var PopupStringB = Text(myFeature.TotalGHG, '###,###.0')
DefaultValue(popupStringB, 'no data')
Any ideas?
Sorry about that. There was an extra "=" that I overlooked. Try this
var filterStatement = "FacilityID = @this AND FiscalYear = '2021-2022'";
That worked!! Thanks for the help.