Apply date range selector to filter indicators with data expressions

509
4
Jump to solution
12-11-2023 04:53 AM
Labels (1)
Tiff
by
Occasional Contributor III

I have custom data expressions for indicators to sum up various fields in my feature layer. The expression is written by creating a dictionary for all the fields that I want to eventually filter by through category selectors. These are all either integer or string fields, like "County Name" or "Year".

Is it possible to incorporate a date range selector that would somehow be compatible with the category selector filter actions? Since each selector's filter actions asks for a source and target field, I'm finding it difficult to figure out if this type of interaction is possible. Any thoughts appreciated, thank you!

1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

A date selector just needs a date field to act against, so you should just be able to include a date field in the expression. Define the date field in your combinedDict object, then pull the date field in from the feature in your loop later.

If this is on Portal, you'll need to use Number to get your date to come through correctly.

var combinedDict = {
  "fields": [
    {'name': 'WATERSHED','type':'esriFieldTypeString'},
    {'name': 'GROUP_NAME','type':'esriFieldTypeString'},
    {'name': 'Weights','type':'esriFieldTypeInteger'},
    {'name': 'some_date', type: 'esriFieldTypeDate'}
  ],
  "geometryType": "",
  "features": []
}

var i = 0
for (var f in fs) {
  combinedDict.features[i++] = {
    "attributes": {
      "WATERSHED": f["WATERSHED"],
      "GROUP_NAME": f["GROUP_NAME"],
      "Weights": f["FIELD_1"] * 25 + f["FIELD_2"] * 22 + f["FIELD_3"] * f["FIELD_4"],
      some_date: Number(f['some_date'])
  }
}
var result = FeatureSet(Text(combinedDict))
return result

 Once your featureset has a date field in it, any date selector should be able to act against it.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
4 Replies
jcarlson
MVP Esteemed Contributor

It's important to remember that an Indicator widget can do the summing for you.

When you return a sum in the Data Expression, any other non-summed fields are stripped out, and you can't filter by them. Instead, try returning a Data Expression with a single row per item. Then set the Indicator to show a Statistic and choose Sum. The underlying data can have per-item date values, and thus be filtered by a date selector.

This would be easier to advise on with your expression. Can you share it?

- Josh Carlson
Kendall County GIS
0 Kudos
Tiff
by
Occasional Contributor III

Hi @jcarlson, thanks for chiming in! I wonder if the calculation I am doing would work with how you are describing using the Indicator widget. Not only am I summing up fields, I am also applying other dynamic calculations, for example, multiplying one field by another or a specific value. 

Here is a shortened expression example after pulling in the item from Portal, in which the two category selector in this case would be watershed and group name. I wasn't able to figure out how to incorporate this into an Indicator, which is why I went the data expression route.

var combinedDict = {
  "fields": [
    {'name': 'WATERSHED','type':'esriFieldTypeString'},
    {'name': 'GROUP_NAME','type':'esriFieldTypeString'},
    {'name': 'Weights','type':'esriFieldTypeInteger'}
  ],
  "geometryType": "",
  "features": []
}

var i = 0
for (var f in fs) {
  combinedDict.features[i++] = {
    "attributes": {
      "WATERSHED": f["WATERSHED"],
      "GROUP_NAME": f["GROUP_NAME"],
      "Weights": f["FIELD_1"] * 25 + f["FIELD_2"] * 22 + f["FIELD_3"] * f["FIELD_4"]
  }
}
var result = FeatureSet(Text(combinedDict))
return result
0 Kudos
jcarlson
MVP Esteemed Contributor

A date selector just needs a date field to act against, so you should just be able to include a date field in the expression. Define the date field in your combinedDict object, then pull the date field in from the feature in your loop later.

If this is on Portal, you'll need to use Number to get your date to come through correctly.

var combinedDict = {
  "fields": [
    {'name': 'WATERSHED','type':'esriFieldTypeString'},
    {'name': 'GROUP_NAME','type':'esriFieldTypeString'},
    {'name': 'Weights','type':'esriFieldTypeInteger'},
    {'name': 'some_date', type: 'esriFieldTypeDate'}
  ],
  "geometryType": "",
  "features": []
}

var i = 0
for (var f in fs) {
  combinedDict.features[i++] = {
    "attributes": {
      "WATERSHED": f["WATERSHED"],
      "GROUP_NAME": f["GROUP_NAME"],
      "Weights": f["FIELD_1"] * 25 + f["FIELD_2"] * 22 + f["FIELD_3"] * f["FIELD_4"],
      some_date: Number(f['some_date'])
  }
}
var result = FeatureSet(Text(combinedDict))
return result

 Once your featureset has a date field in it, any date selector should be able to act against it.

- Josh Carlson
Kendall County GIS
0 Kudos
Tiff
by
Occasional Contributor III

Hi Josh, this worked amazingly. Thank you SO much. I think I wasn't sure how it would address the date range, but I see now that the date range selector is compatible in that it can filter the table to pull all features that apply. Thank you again.

0 Kudos