Select to view content in your preferred language

Help with a Arcade Popup expression

617
4
Jump to solution
02-17-2023 07:26 AM
Labels (1)
RandyMcGraw1
New Contributor III

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

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Sorry about that. There was an extra "=" that I overlooked. Try this

var filterStatement = "FacilityID = @this AND FiscalYear = '2021-2022'";

 

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

 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') 

 

0 Kudos
RandyMcGraw1
New Contributor III

Hello KenBuja,

Thank you for taking the time.

I tried your suggestion but get the following result:

RandyMcGraw1_0-1676666546001.png

 

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?

0 Kudos
KenBuja
MVP Esteemed Contributor

Sorry about that. There was an extra "=" that I overlooked. Try this

var filterStatement = "FacilityID = @this AND FiscalYear = '2021-2022'";

 

0 Kudos
RandyMcGraw1
New Contributor III

That worked!! Thanks for the help.

0 Kudos