Select to view content in your preferred language

Arcade Filtering With Timeline Widget

208
4
07-28-2025 10:27 AM
quich12345
New Contributor

Hello, I have a question regarding if anyone has worked out the logic behind how arcade interacts with temporal data using the timeline. I have an arcade script within my dynamic text, it essentially is instructing the text to ignore the 0 values within the data. The arcade script works but displays all of the features within the dataset. My understanding is that the timeline widget is filtering the framework of the layer I am working with. I have made sure that everything is wired up correctly, by using a control of normal dynamic text. This control is filtering as expected when the timeline widget changes. The arcade script doesn't have anything included in it about temporal filtering, because I would expect the timeline widget to filter the data framework which the arcade script is pulling from. Has anyone encountered issues with arcade and filtering with other widgets? 

0 Kudos
4 Replies
Marshal
Frequent Contributor

Edit

I think misunderstood the issue, so let me try again.

Are you saying the timeline widget is not correctly filtering the content in your dynamic text widget?

1)  What environment are you in? AGOL vs Enterprise?  What versions?

1)  What widget are you using dynamic text in?

2)  Is the same layer being used in dynamic text widget wired to the timeline widget?

3)  Is the layer in the dynamic text widget and the timeline filter both using the same view? (e.g. default)

I did a test using dynamic text in a list widget, and the same layer wired to a timeline widget.  The timeline widget was correctly filtering the content in my list widget as I moved between time steps.  I used a simple Arcade expression (ex. {Name} + " " + {Date}) to confirm the data was filtering.

As ShengdiZhang mentioned, Arcade in ExB widgets, specifically configuring dynamic text, is much more limited in functionality than other contexts.  Which was the intent of my original post; that Arcade expressions in dynamic text are likely not the best place to be filtering data.

Original Response

While this doesn't answer you question directly, I hope it helps give some potential ideas for workarounds.

Do you need the 0 values in the data at all?  Do you have control of the experience, map or map service?

If you don't need the 0 values and you have control at one of those levels, here are some options to achieve the desired results.

1) If using ArcGIS Online or Experience Builder Developer 1.18; you can add data to the experience using arcade expressions to pre-filter the data only in the context of that particular experience (preferred).

2) Set a filter on that layer in the map connected to the experience

3) Or as last resort, publish the layer with a definition query to perform the filtering.  Although this may affect other use cases of this layer inadvertently, so it may be a bit dangerous.  Be sure you understand all use cases before republishing.

0 Kudos
ShengdiZhang
Esri Regular Contributor

Hi @quich12345 ,

Currently, Arcade does not support temporal filtering a data source directly using built-in functions. However, you can work around this limitation by reading the time extent of the data source and then building a SQL expression to apply the filter manually.

If your data is in UTC time zone, here is a sample script you can use:

// Retrieve the time extent from the data source
var dataSource = $dataSources["dataSource_1-0"];
var startTime = dataSource.queryParams.timeExtent.start;
var endTime = dataSource.queryParams.timeExtent.end;

// Convert time values to UTC and format as SQL-compatible timestamps
var formattedStartTime = Text(ToUTC(startTime), 'Y-M-D h:mm:ss');
var formattedEndTime = Text(ToUTC(endTime), 'Y-M-D h:mm:ss');

// Build SQL
var sqlTimeFilter = "Date BETWEEN TIMESTAMP '" + formattedStartTime + "' AND TIMESTAMP '" + formattedEndTime + "'";

// Apply the filter to the data source layer
var filteredLayer = Filter(dataSource.layer, sqlTimeFilter);

// Return the count of filtered records
return Count(filteredLayer);

Please let me know if the script doesn't work or if you have other questions.

Thanks,
Shengdi

0 Kudos
TimHaverlandNOAA
Regular Contributor

@ShengdiZhang when Filter(dataSource.layer, sqlTimeFilter) in the example is run, does that actually filter the original data source (so widgets using that datasource would show the filtered results) or is it just returning an in-memory featureSet that we can work with in Arcade? Based on my testing it seems like the Filter function is just returning a feature set in Arcade.

0 Kudos
ShengdiZhang
Esri Regular Contributor

@TimHaverlandNOAA

You're right—the filter function in Arcade only applies within the Arcade expression and does not affect the original data source.

Filters applied through other widgets should be synced automatically in Arcade. However, due to some current limitations, you'll need to handle the filtering logic within the Arcade script manually.

0 Kudos