Select to view content in your preferred language

Return day of year from date field for Serial Chart using Arcade

889
4
Jump to solution
10-12-2022 08:20 AM
DataOfficer
Regular Contributor

Hello,
I am looking for a way to use Arcade in Dashboards to return the day of the year from a date field.
Due to the lack of Globals in Arcade for Dashboards, I have first called the FeatureSet using FeatureSetByPortalItem.

 

var p = 'https://www.arcgis.com'
var itemId = '998628deb4b144e8a17afd9ab606d700' // note this is an example ID from a different service
var fs = FeatureSetByPortalItem(Portal(p), itemId, 0, ['*'], false)

 

I am then looking for a way to use either the ISOWeek or Text functions (Text(date, DDD) to return the week or day from a date field within the FeatureSet. So far I've been unsuccessful in finding a way to pull out the date field (called RecordDate_rep) from the FeatureSet to then call the week/day functions mentioned above. I presume I'm missing something obvious, but any help is appreciated.

I was then attempting something like this, but it doesn't work, returning "Execution Error:Runtime Error: Cannot call member property on object of this type.":

 

var dat = fs.RecordDate; // extract Date field from FeatureSet
var day = Text(dat, 'DDD'); // Format date as day of year
return day; // output day of year

 

 @XanderBakker if you are able to assist on this I would greatly appreciate it.

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

If you use the data from the itemID in your message, it works correctly

 

var p = 'https://www.arcgis.com'
var itemId = '998628deb4b144e8a17afd9ab606d700';
var fs = FeatureSetByPortalItem(Portal(p), itemId, 1, ['*'], false) //layerId 0 doesn't have a date field
var feature = First(fs);
var theDate = feature.LastMaintenance;
var theDay = Text(theDate, 'DDD');
return `${theDay} (${Text(theDate,'MMM D, YYYY')})`;

//returns 47 (Feb 16, 2021)

 

 

View solution in original post

4 Replies
KenBuja
MVP Esteemed Contributor

If you use the data from the itemID in your message, it works correctly

 

var p = 'https://www.arcgis.com'
var itemId = '998628deb4b144e8a17afd9ab606d700';
var fs = FeatureSetByPortalItem(Portal(p), itemId, 1, ['*'], false) //layerId 0 doesn't have a date field
var feature = First(fs);
var theDate = feature.LastMaintenance;
var theDay = Text(theDate, 'DDD');
return `${theDay} (${Text(theDate,'MMM D, YYYY')})`;

//returns 47 (Feb 16, 2021)

 

 

DataOfficer
Regular Contributor

Thank you for your help on this. Testing the code you provided shows this works with my data too. However in Dashboards, when I click Done, it shows thee is an issue with the Data expression and doesn't let me use it for the Serial Chart. Hovering on the warning symbol shows the warning: "Unable to execute Arcade script"

DataOfficer_0-1665590644283.png

I'm assuming I need to return a FeatureSet rather than a value. Do I need to create a data schema (as suggested in this thread: https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-data-expression-quot-unab...)? In my case, I will need to return the number of records per unique day of the year.

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Yes, create a dictionary from the result and return it like in the example @XanderBakker provides.

DataOfficer
Regular Contributor

Thanks, I managed to get it working, but by week instead of day.

0 Kudos