Use Category Selector as a Yes or No?

487
2
Jump to solution
07-22-2022 09:09 AM
RobertStanionis
New Contributor II

Hello,

I created a dashboard that shows crime data to our citizens. In the feature, I added a Press Release column that I add a URL to the specific press release related to that crime.

I want to create a tool that would allow the user to just see crime incidents that have a press release associated with them.

Is there a way to use the category selector to show only incidents that have a URL in the press_release column of the feature? I'm thinking I would need to use the Defined values option and set up some value that would select the rows that are not null and then filter.

 

Thanks for the help!

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

If you used a Data Expression, you could create a filter based on whether the URL was null or not, but then you might have trouble connecting that selector back to the original data, unless that Data Expression also was referenced by most of your other non-map widgets.

var portal = Portal('your portal url')

var fields = [
    'array',
    'of',
    'field',
    'names',
    'you',
    'need'
]

// make sure the objectid is one of the fields you include!

var fs = FeatureSetByPortalItem(
    portal,
    'itemid of service',
    0, // or whatever index the layer is
    fields,
    False
)

return GroupBy(
    fs,
    fields,
    {
        name: 'has_pr',
        expression: 'CASE WHEN press_release IS NULL THEN 0 ELSE 1 END',
        statistic: 'SUM'
    }
)

 

In short, this would basically give you back the same set of features you put into it, with all the same fields, but with a new field tacked on, called has_pr. This field will be a 0 when the press release URL field is null, and 1 when it has a value present.

You'd be able to configure any non-map widgets to look at this Data Expression to show things like a list, statistical indicators, and the like, and interactions with other widgets like a list or chart could be used to filter features in the map by linking their objectid fields.

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

If you used a Data Expression, you could create a filter based on whether the URL was null or not, but then you might have trouble connecting that selector back to the original data, unless that Data Expression also was referenced by most of your other non-map widgets.

var portal = Portal('your portal url')

var fields = [
    'array',
    'of',
    'field',
    'names',
    'you',
    'need'
]

// make sure the objectid is one of the fields you include!

var fs = FeatureSetByPortalItem(
    portal,
    'itemid of service',
    0, // or whatever index the layer is
    fields,
    False
)

return GroupBy(
    fs,
    fields,
    {
        name: 'has_pr',
        expression: 'CASE WHEN press_release IS NULL THEN 0 ELSE 1 END',
        statistic: 'SUM'
    }
)

 

In short, this would basically give you back the same set of features you put into it, with all the same fields, but with a new field tacked on, called has_pr. This field will be a 0 when the press release URL field is null, and 1 when it has a value present.

You'd be able to configure any non-map widgets to look at this Data Expression to show things like a list, statistical indicators, and the like, and interactions with other widgets like a list or chart could be used to filter features in the map by linking their objectid fields.

- Josh Carlson
Kendall County GIS
RobertStanionis
New Contributor II

Thank you. I will give this a try.

 

0 Kudos