Data Expression to Reshape Attribute Table Removes Ability to Filter Map

694
3
03-11-2022 04:17 PM
JoshuaFlickinger
New Contributor III

Background

I have a feature service in this format:

Trail_NameGroup1_InspectionGroup2_InspectionGroup3_Inspection
Trail 1Not InspectedInspectedInspected
Trail 2InspectedInspectedInspected

 

I needed to re-arrange the data for graphing in a dashboard, so I figured out how to use a Data Expression to reshape the attribute table into this format:

Trail_NameInspection_GroupInspection_Status
Trail 1Group1Not Inspected
Trail 2Group1Inspected
Trail 1Group2Inspected

And so on...

Essentially, this way I could graph by Inspection Group and split the data in the graph by Inspection Status so I could display in the dashboard how many groups have completed their various inspections.  Assuming the method to the madness matters, you can see essentially how I did this in the code snippet at the end of the post.  The code works, and I'm able to create a graph the way I wanted.  However...

Question

The issue I'm having is that my graph does not allow me the option to filter my map, based on column selection.  When I try to configure the chart properties for filtering, it wants me to specify destination and target fields.  Well, I retained trail name in an attempt to make this work, but it doesn't allow that as an option.  So, I'm trying to figure out whether that was due to the way I split up my data through my data expression - or alternatively if it's just not possible after the data re-arrange.  Anybody have any clues?

Thanks.

Code Appendix

var portal = Portal('https://www.arcgis.com/');
var fs = FeatureSetByPortalItem(
    portal,
    '1234567890',
    0,
    [
        'TRLNAME',
        'Group1_Inspection',
        'Group2_Inspection',
        'Group3_Inspection'
    ],
    false
);

var g1 = GroupBy(fs, ['Group1_Inspection', 'TRLNAME'], [{name: 'Count', expression: "1", statistic: 'COUNT'}])
var g2 = GroupBy(fs, ['Group2_Inspection', 'TRLNAME'], [{name: 'Count', expression: "1", statistic: 'COUNT'}])
var g3 = GroupBy(fs, ['Group3_Inspection', 'TRLNAME'], [{name: 'Count', expression: "1", statistic: 'COUNT'}])

var features = [];
var feat;

for (var g in g1) {
    feat = {
        attributes: {
            TRLNAME: g['TRLNAME'],
            inspection_group: 'Group1',
            inspection_status: g['Group1_Inspection'],
            Combined_Segment_count: g['Count']
        }
    };
    Push(features,feat);
}

for (var g in g2) {
    feat = {
        attributes: {
            TRLNAME: g['TRLNAME'],
            inspection_group: 'Group2',
            inspection_status: g['Group2_Inspection'],
            Combined_Segment_count: g['Count']
        }
    };
    Push(features,feat);
}

for (var g in g3) {
    feat = {
        attributes: {
            TRLNAME: g['TRLNAME'],
            inspection_group: 'Group3',
            inspection_status: g['Group3_Inspection'],
            Combined_Segment_count: g['Count']
        }
    };
    Push(features,feat);
}

var fsDict = {
    'fields': [
        {'name':'TRLNAME', 'type':'esriFieldTypeString'},
        {'name':'Inspection_Group', 'type':'esriFieldTypeString'},
        {'name':'Inspection_Status', 'type':'esriFieldTypeString'},
        {'name':'Combined_Segment_Count', 'type':'esriFieldTypeInteger'}
    ],
    'geometryType': '',
    'features': features,
}

return FeatureSet(Text(fsDict));
0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

I can't see a reason why this would happen. I have data expression layers filtering map layers in exactly the way you are attempting to do yourself.

Is it, by chance, a Map Image layer, as opposed to a Feature Layer?

When you attempt to add the action between the chart and the map, what, if anything, do you see?

- Josh Carlson
Kendall County GIS
0 Kudos
JoshuaFlickinger
New Contributor III

Hi Josh - I actually used some of your other responses here on GeoNet to work out how to re-arrange my data; in case you don't hear it enough, thanks for being a contributor.  I'm sure I'm not alone in having learned from your experience/expertise.

I'm talking to a feature layer, not a map image layer, but I did figure out the issue.  I was charting off of Inspection Group and Inspection Status.  I thought Trail Name could still be used as a filter, but I overestimated the ability of the Dashboard in that respect.  When I charted off of Trail Name, the filter worked.

One additional issue I noticed is that, when attempting to filter the chart based on map extent, the whole chart breaks down.  It will just return 'No Data'.  To the best of your knowledge, is that just a limitation of the data expressions?  I'm guessing it's just too much processing to occur any time the map is adjusted.

0 Kudos
jcarlson
MVP Esteemed Contributor

Glad you figured it out!

The key to that second issues is this:

geometryType: ''

Without including the geometry of your features, there's nothing for the map to act against.

You can include the geometry in your output, but your expression will suffer decreased performance. Since you're grouping, you'd need to somehow perform a Union somewhere in your expression, and that kind of thing can get pretty "expensive" in terms of compute time.

- Josh Carlson
Kendall County GIS