Separate the options the user selected in Survey123

1397
3
09-13-2021 06:15 AM

Separate the options the user selected in Survey123

Hello,

I have a layer of features called 'Panéis'.
A field called 'Manutencoes' on this layer has a list with several options:
- Troca de ferro para fixação das lonas
- Troca de chapa enferrujada
- Revitalização de pontos de ferrugem
- Instalação de cantoneiras
- Troca de refletores
- Troca de fiação
- Troca de parafuso e/ou Instalação de parafuso
- Pintura do posto
- Substituição do componente do desjuntor e foto célula

Image-01.jpg

I used this feature layer to create a form in Survey123.

Image-02.jpg

All options selected in the form are stored in the field 'Manutencoes', separated by ','.

When creating the chart in the dashboard, the options are not separated.

Image-03.jpg

How can I separate the options the user selected in Survey123?

Regards, Diego

Comments

Hi @DiegoMendes_Rodrigues 

Please see the Understanding Multiple-Choice Questions in Survey123 for ArcGIS blog post, in particular the Controlling how user selections are stored in ArcGIS section, which details a method for separating out the user's selections for a select_multiple into individual hidden fields using a combination of if() and selected() functions.

Also please note you can post questions in the ArcGIS Survey123 Questions section of the Esri Community (noting that this post is in Documents).

Best, Jim

Another option is using a variation of this code that @JohannesLindner wrote; I'm using it for my post-processing workflow right now since it saves space in the excel sheet while setting up the survey.

The end result will be a new record for each option selected in the question. Make sure to test it on fake data before applying it to your real data; it functions by completely rewriting your output table.

https://community.esri.com/t5/data-management-questions/using-python-to-unpivot-a-table/m-p/1090280/...

Spoiler
# your input table and fields
in_fc = "..."
in_fields = ["OBJECTID", "RELID", "DATE", "AUTHORS"]

# your output table and fields
# this can be in_fc and in_fields, but for testing I suggest you create a new table...
# if you really need to copy ObjectID, you have to create a new field, FID in my example
out_fc = "..."
out_fields = ["FID", "RELID", "DATE", "AUTHORS"]

# index of the field that has to be split
# !python uses zero-based indexing!
split_field_index = 3
split_pattern = ", "


# read data
data = [list(row) for row in arcpy.da.SearchCursor(in_fc, in_fields)]

# optional: delete all rows from out_fc
# !!! if out_fc is the origin table of a relationship class, the foreign key in the related table will be set to Null !!!
arcpy.management.TruncateTable(out_fc)

with arcpy.da.InsertCursor(out_fc, out_fields) as cursor:
    # loop through original data
    for row in data:
        split_field = row[split_field_index]
        # split_field is empty? just copy the row
        if split_field is None:
            cursor.insertRow(row)
            continue
        # split split_field 
        split_values = split_field.split(split_pattern)
        # loop through split_values and insert rows
        for value in split_values:
            row[split_field_index] = value
            cursor.insertRow(row)

 

No way in the form.  Must post process.  Select multiple is a data pain for sure.

One cool way for charts is to use Ops Dashboard see an example here  

https://www.esri.com/arcgis-blog/products/ops-dashboard/announcements/introducing-data-expressions-i...

Good luck

Version history
Last update:
‎09-13-2021 06:15 AM
Updated by: