Hi everyone,
I am a bit new to using Arcade and I was wondering if I could get some assistance. I have a singular feature set which contains a date field (as a date type), and a string field for a device name (of which there are multiple) and a double field which contains values of percentage of a chemical that we are measuring. Basically we have devices A, B and C out in a field measuring for a chemical and the table gets updated every month with the date data is manually captured and the chemical data percent value added next to each new line for each device. Due to the software that our field team uses, the date information is captured with a time stamp.
The data would look something like this:
| Device | Date | Chemical % |
| A1 | 01/04/2022 | 50 |
| A2 | 01/04/2022 | 49.8 |
| A3 | 01/04/2022 | 51.2 |
| A1 | 01/05/2022 | 49.2 |
| A2 | 01/05/2022 | 51.2 |
| A3 | 01/05/2022 | 48.2 |
As you can see, the table keeps expanding with new data being added to it based on that month's readings.
With the guidance of the following support article I am trying to organise my data to show a list of the devices and their monthly change:
https://www.esri.com/arcgis-blog/products/ops-dashboard/analytics/enhancing-dashboard-elements-using-data-expressions-part-2/
However I am finding that I am having syntax issues when trying to filter the FeatureSet by date when defining a variable. At first I thought it was an issue with the date field, so i created a new field called DateText and converted the feature to a normal string field. It does not seem to error with defining the below currentDate and monthAgo variables however when trying to define the today and lastMonth variable it is throwing syntax errors:
var MethaneReport = FeatureSetByPortalItem(Portal('https://ORGANISATION.maps.arcgis.com'),"FEATURE-SET-UUID", 0,["*"],false);
var combinedDict = {
fields: [
{name: "Device", type: "esriFieldTypeString"},
{name: "Date", type: "esriFieldTypeString"},
{name: "Chemical", type: "esriFieldTypeString"},
{name: "current", type: "esriFieldTypeString"},
{name: "month_ago", type: "esriFieldTypeString"},
],
geometryType: "",
features: [],
};
// Iterate through features to find most current date
var currentDate = Text(Date(Max(combinedDict, 'DateText')), "DD-MM-YYYY");
var monthAgo = Text(DateAdd(currentDate, -31, "days"), "DD-MM-YYYY");
// Use most current date as a filter
var today = OrderBy(Filter(combinedDict, "(DateText= @currentDate) AND (Device_ID NOT IN ('A4','A5','A6'))"), 'Device_ID');
// Filter and retrieve rows that correspond to a month ago
var lastMonth = OrderBy(Filter(combinedDict, "(DateText = @monthAgo) AND (Device_ID NOT IN ('A4','A5','A6'))"), 'Device_ID');
The fields in the tables are defined as Device_ID and DateText.
It is all looking fine up until I start to include the today and lastMonth variables into the code and it errors as below:
Execution Error:Filter cannot accept this parameter type.
I am sure that the syntax/logic I am using is wrong but I cannot quite spot where. I was wondering if anyone could please lend some advice?