Hello, I'm fairly new to Arcade and I'm trying to build a data expression inside a gauge on Dashboard. I'm able to navigate to my portal layer using the following code:
var p = Portal("Organization Portal");
var feature = FeatureSetByPortalItem(p, "Item ID", Layer ID);
Now I'm trying to apply a filter to the layer. The following is what was applied to my feature layer in ArcGIS Pro as a whole before publishing as a web map. My goal is to build a gauge for each date range in order to track the counts. How would I do that here? Thanks.
//hydrants that were flow tested within a year from today
if (DateDiff(Now(), Date($feature.TEST_DATE), 'days') < 365)
{return "Tested within a year from today"}
//hydrants that were flow tested over a year from today
else if (DateDiff(Now(), Date($feature.TEST_DATE), 'days') >= 365 &&
DateDiff(Now(), Date($feature.TEST_DATE), 'days') < 730)
{return "Tested over a year from today"}
//hydrants that were flow tested over two years from today
else if (DateDiff(Now(), Date($feature.TEST_DATE), 'days') >= 730 &&
DateDiff(Now(), Date($feature.TEST_DATE), 'days') < 1460)
{return "Tested over two years from today"}
//hydrants that were flow tested over three years from today
else if (DateDiff(Now(), Date($feature.TEST_DATE), 'days') >= 1460)
{return "Tested over three years from today"}
//hydrants that were never tested
else
{return "No ISO information"}
Here's an example of how to filter your data by time. This filters recent earthquakes, returning quakes between one and two months ago.
var p = Portal("https://www.arcgis.com");
var fs = FeatureSetByPortalItem(p, '9e2f2b544c954fda9cd13b7f3e6eebce', 0, ['eventTime'])
var time1 = Dateadd(Today(), -1, 'month')
var time2 = Dateadd(Today(), -2, 'month')
var sql = `eventTime < '${time1}' and eventTime > '${time2}'`
return Filter(fs, sql)