Can you cast data from string field type to date for use in dashboard date selector

325
3
04-19-2021 11:53 AM
Labels (3)
LeeIrminger
New Contributor II

Can you use Arcade to change a field type from Text to Date on the fly for use with a dashboard date selector? I see how it can be done in a pop up, but that doesn't interact with the date selector.

 

It looks like a data expression would work. Are there any examples similar to my use case?

 

Thank you,

0 Kudos
3 Replies
DavidPike
MVP Frequent Contributor

yeh I'd definitely say a data expression.  Syntax would be exactly the same as the popup, except that you would reference the feature first by something like:

 (abridged example from Data Functions | ArcGIS for Developers)

var portal = Portal('https://www.arcgis.com');
var features = FeatureSetByPortalItem(portal, '7b1fb95ab77f40bf8aa09c8b59045449')

I can't really offer you an example of the date string to datetime/Esri date without knowing what the string looks like, but here are some example methods Date Functions | ArcGIS for Developers.

jcarlson
MVP Notable Contributor

Unfortunately, you can't get Arcade to work like that in the dashboard. A date selector is "layer agnostic", so to speak, and can't work with non-attribute data, as it is essentially just submitting an SQL query to the feature service.

If you watch the network traffic on your browser, you can see it happen:

jcarlson_0-1618869419607.png

Picking that option sends this to request (relevant part bolded):

{"GET":
{
"scheme":"https",
"host":"services6.arcgis.com",
"filename":"/U1zX3Wx8hhY7Gb30/arcgis/rest/services/Sales_Hosted/FeatureServer/0/query",
"query":{
"f":"json",
"cacheHint":"true",
"groupByFieldsForStatistics":"sale_year,valid_sale",
"orderByFields":"sale_year ASC",
"outFields":"*",
"outStatistics":"[{\"onStatisticField\":\"id\",\"outStatisticFieldName\":\"value\",\"statisticType\":\"count\"}]",
"resultType":"standard",
"returnGeometry":"false",
"spatialRel":"esriSpatialRelIntersects",
"where":"(sale_date>timestamp '2006-01-02 05:59:59' AND valid_sale=0) AND (sale_date BETWEEN timestamp '2020-01-01 06:00:00' AND timestamp '2021-01-01 05:59:59')"
}}}

 

The only way to get a date filter to work would be to create a true date field. You wouldn't be the first person to create a new field for the sake of a dashboard!

Does the text field consistently contain date values? And is there a reason to maintain it as a text field instead of just converting it?

- Josh Carlson
Kendall County GIS
DavidPike
MVP Frequent Contributor

On looking at the question again, it's not going to be easy, but theoretically you could iterate through the original values and create a text representation of the JSON to create a new feature set with all the existing and new date values - but it's far from trivial.