Select to view content in your preferred language

Dashboards & Data Expressions Query

383
2
10-08-2024 07:21 AM
Labels (1)
JWeiss_AP
Emerging Contributor

My colleague (who can't access this page due to getting a blank screen after logging in) has the following issue regarding an integration between Survey123 and a Dashboard.

He has a survey in Survey123 which is connected to a feature layer in Enterprise. A dashboard is then built on the web map connected to that feature layer. The aim is to have all incidents in the survey visualized in a dashboard with pie charts and bar graphs responded on the map extent and date filtered. However, for the multiple choice questions, when more than one choice is selected in Survey123 the field which is created in the Enterprise feature layer contains each answer that was selected separated by commas. For example, if the question is "What crops were raided" and someone selects three different crops the answer looks like this: "Beans, Maize, Bananas". This tends to clutter the dashboard pie chart as Beans are not counted as Beans only and every list-like answer is shown as a separate slice. Even if the order in which the choices were selected changes it is seen as a separate category/slice on the pie chart (e.g. "Maize, Beans, Bananas" is a separate slice from "Beans, Maize, Bananas"). Ideally, he would want a slice for each crop type counting on the number of surveys where the crop type was selected within the list of other crop types.

He has tried playing around with data expressions and actually managed to get a table which could be counted on separate crop types, but the pie chart is no longer actionable by map extent or the date filter. Any guidance on the how to resolve this and whether this is actually possible in ArcGIS Dashboards at all, would be greatly appreciated. The pie chart under the Survey123 Analysis tab seems to be reading crop type separately, hence he believes it is an integration issue.

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

It should be possible, but it really depends on the expression. If you write the expression in such a way to include the geometry, your widgets using that expression can be acted upon by the map.

In this map, the two circled layers are from a data expression; they're not actually in the map shown.

jcarlson_0-1728399299806.png

Because the geometry is available to the layer, as I move the map, the items change:

jcarlson_1-1728399351662.pngjcarlson_2-1728399363029.png

Can you share the expression? Basically, when you're pushing your split values into the output featureset, you need to include the geometry at that point, but it depends on how you're writing your data expression.

- Josh Carlson
Kendall County GIS
0 Kudos
JWeiss_AP
Emerging Contributor

Hi Josh,

Thanks so much for the quick response. I will add the geometry field to the table and see if that works. In the meantime I had already added a field named 'date_time_of_incident' and labelled ‘Date & time of incident’ to the table being used on the visual using the data expression. The end goal is to select for date and time on the pie chart named ‘crop type’ in the dashboard. The name is the same on the selector on the dashboard but for some reason the action does not want to load the target field name (ie. looking for ‘Date & time of incident’ as in the bar chart visual below) for selection. Before I added the field name to the data expression table the visual (ie. pie chart called crop type) did not show under actions on the date selector at all so at least now it shows. This makes me skeptical about the geometry working on the map extent.

 

Below is the data expression which splits the multiple crops selected in the survey into separate rows. This allows each crop type to be counted using the unique fid (‘FID’ field) in the pie chart. The following fields are created {'split_choices', ‘FID’, ‘date_time_of_incident’.

 

// Dictionary of valid crops with proper case normalization

var cropMap = {

   'cassava': 'Cassave',

   'maize': 'Maize',

   'beans': 'Beans',

};

 

// Empty dictionary to capture each hazard reported as separate rows

var choicesDict = {

   'fields': [

       { 'name': 'split_choices', 'type': 'esriFieldTypeString' },

       { 'name': 'FID', 'type': 'esriFieldTypeOID' }, // Include FID

       { 'name': 'date_time_of_incident', 'type': 'esriFieldTypeString', 'alias': 'Date & time of incident' } // Include date_time_of_incident with an alias

   ],

   'geometryType': '',

   'features': []

};

 

var index = 0;

 

// Loop through each feature to capture raw date and crop data

for (var feature in fs) {

   var date_time = feature['date_time_of_incident'];  // Capture the date and time

   var fid = feature['OBJECTID']; // Assuming OBJECTID is the FID

 

   // Split comma-separated crop types and store in dictionary

   var split_array = Split(feature["what_crops_were_destroyed"], ',');

   var count_arr = Count(split_array);

  

   for (var i = 0; i < count_arr; i++) {

       var crop = Lower(Trim(split_array[i]));  // Convert to lowercase for matching

      

       // Check if the crop exists in the cropMap, otherwise categorize as 'Other'

       if (HasKey(cropMap, crop)) {

          choicesDict.features[index++] = {

              'attributes': {

                  'split_choices': cropMap[crop],

                  'FID': fid,

                  'date_time_of_incident': Text(date_time) // Store the date_time_of_incident

               }

           };

       } else {

          choicesDict.features[index++] = {

              'attributes': {

                  'split_choices': 'Other',

                  'FID': fid,

                  'date_time_of_incident': Text(date_time) // Store the date_time_of_incident

               }

           };

       }

   }

}

 

// Convert dictionary to featureSet

var fs_final = FeatureSet(Text(choicesDict));

return fs_final; // Return the final FeatureSet

 

JWeiss_AP_1-1728463157038.png

JWeiss_AP_0-1728463157037.png

0 Kudos