Select to view content in your preferred language

How to filter data in a data expression

85
3
Jump to solution
Tuesday
ChuckS
by
Occasional Contributor

I'm new to using Data Expressions in Dashboards. I'm not sure if what I'm trying to do is simple or complex. My data expression is from a similar dashboard from a colleague.

I'm creating a Table dashboard element that uses a data expression. Currently, I only have 5 records in my feature layer. Elsewhere in the dashboard, I have 3 Category Selectors which have Actions that filter data displayed in my Table element. The default selection for the Category Selectors would only display 3 records in the Table.

When I use FeatureSetByPortalItem in the data expression for the Table (shown below), it gets ALL records from the feature layer. How do I access only the records which are filtered by the Category Selectors? I'm iterating through the records to get the most recent record for a specific value in a field, but the result is a record which is not displayed (based on the Category Selectors).

var originalLayer = FeatureSetByPortalItem(
  Portal('https://arcgis.com/'), 
  myFeatureLayerID,
  0
);

 

0 Kudos
1 Solution

Accepted Solutions
JenniferAcunto
Esri Regular Contributor

When you create a dashboard element from a hosted feature layer, you connect it to all the data and then point category selectors at that element to create dynamic filters. Data expression work the same way. Your data expression should return all relevant data which is used to create a dashboard element, such as a table, and then you point the category selectors to the table element. 

In order for your category selector to play nice with your table element, you need to ensure that your data expression returns the fields used in your category selector. For example, if I have a category selector to filter based on storm types (hail, snow, rain), then I need to ensure that my data expression returns a storm type field with corresponding values. 

- Jen

View solution in original post

3 Replies
JenniferAcunto
Esri Regular Contributor

When you create a dashboard element from a hosted feature layer, you connect it to all the data and then point category selectors at that element to create dynamic filters. Data expression work the same way. Your data expression should return all relevant data which is used to create a dashboard element, such as a table, and then you point the category selectors to the table element. 

In order for your category selector to play nice with your table element, you need to ensure that your data expression returns the fields used in your category selector. For example, if I have a category selector to filter based on storm types (hail, snow, rain), then I need to ensure that my data expression returns a storm type field with corresponding values. 

- Jen
ChuckS
by
Occasional Contributor

Thank you for you response. It helped me find a solution. It took a long time because I'm trying to modify a data expression without a good background in Python or Arcade. Using the console helped a lot! I do understand programming and know several programming languages.

My dashboard is connected to a survey that is related to fleet management. One of my category selectors has three values: 1) Start of shift, 2) Supervisor check, and 3) Defective equipment. I had to add an outer loop to find the most recent entry (for each vehicle) for each of these category selector values. I made use of Distinct() and Filter(). Without this additional code, it was grabbing the most recent entry for the whole layer. This resulted in a feature set that was missing elements for each value for the category selector.

One thing that drove me crazy was was that every time I modified the data expression, the filter and category field under the Data section for the table would be cleared. This caused my table to have no data, then I'd realize that I had to reset the filter and category field. This happened whether I clicked on Change or Edit when modifying the layer to edit the data expression. I don't know if this is by design or if I should modify the data expression some other way.

0 Kudos
JenniferAcunto
Esri Regular Contributor

Yeah that is annoying. I've found that if you edit the data expression, but cancel out of the element you won't lose your configuration and will still have the updated data expression feeding into it. 

JenniferAcunto_1-1783602816018.png

 

- Jen