Accumulating repeat data in text string outside of repeat in Survey123 Connect

207
2
Jump to solution
02-23-2024 12:22 PM
AK-SavannahThomasDataProjects
New Contributor II

Example.PNGHi! I have a question that seems like it should be super simple, but is taking forever for me to figure out. 

I have three select one question in a survey123 connect XLSForm. I need to create an expression that summarizes these responses across multiple repeats in a string outside of the repeat. Basically I want the user to be able to quickly read what data has been collected in that repeat.

The question/item names are speciesCount, speciesCondition, and Species.

For example, I need to accumulate the results 3 repeat responses. I want it to look like this:

{speciesCount1}  {speciesCondition1} {Species1}, {speciesCount2} {speciesCondition2} {Species2}, {speciesCount3} {speciesCondition3} {Species3}

or

7 Alive Spruce, 9 Dead Aspen, 2 Alive Birch

This expression:

concat(${speciesCount}, " ", ${speciesCondition}, " ", ${Species})

puts the data in the right order but erases data when you add a new repeat.

 

This expression:

join(", ",${speciesCount}, " ", ${speciesCondition}, " ", ${Species})

Accumulates data throughout repeats but it is not in the right order and looks like this:

7,9 ,2, ,Alive,dead,Alive, ,Spruce, Aspen, Birch

${speciesCount1) ,${speciesCount2) , ${speciesCount3), ${speciesCond1},${speciesCond2}, ${speciesCond3}, ${baSpec1}, ${baSpec2}, ${baSpec3}.

 

I then tried to create a hidden row to accumulate data, then another calculate row to display, and another row to see if text display would change anything. This generates an error 'dependency cycles amongst the xpath expression in relevant/calculate\n\nResult: Invalid' or it cycles forever and never updates the form. 

AKSavannahThomasDataProjects_0-1708719475316.png

Hopefully I explained this well but please let me know if I can elaborate more. Any tips or ideas on other ways I could achieve a summary field would be super appreciated. Thank you!! 

0 Kudos
1 Solution

Accepted Solutions
ChristopherCounsell
MVP Regular Contributor
  1. Within the repeat create a row:
    1. type: text
    2. name: speciesrecord
    3. appearance: hidden (or not hidden while testing...)
    4. calculation: concat(${speciesCount}, " ", ${speciesCondition}, " ", ${Species}, "<br>")
    5. Fieldtype = null (so it doesn't create a field)
  2. Create a row outside the repeat to combine the data together:
    1. type: text
    2. name: speciesrecordsummary
    3. appearance: hidden (or not hidden while testing...)
    4. Fieldtype = null (so it doesn't create a field)
    5. Calculation: join('<br>',${speciesrecord})
  3. Create a note field with no name and a label of ${speciesrecordsummary}

This will:

  1. Tidy up each species record within the repeat
  2. Join them together outside the repeat
  3. Display the data via a note label

You can adjust the concatenated text or join separator as desired.

View solution in original post

2 Replies
ChristopherCounsell
MVP Regular Contributor
  1. Within the repeat create a row:
    1. type: text
    2. name: speciesrecord
    3. appearance: hidden (or not hidden while testing...)
    4. calculation: concat(${speciesCount}, " ", ${speciesCondition}, " ", ${Species}, "<br>")
    5. Fieldtype = null (so it doesn't create a field)
  2. Create a row outside the repeat to combine the data together:
    1. type: text
    2. name: speciesrecordsummary
    3. appearance: hidden (or not hidden while testing...)
    4. Fieldtype = null (so it doesn't create a field)
    5. Calculation: join('<br>',${speciesrecord})
  3. Create a note field with no name and a label of ${speciesrecordsummary}

This will:

  1. Tidy up each species record within the repeat
  2. Join them together outside the repeat
  3. Display the data via a note label

You can adjust the concatenated text or join separator as desired.

AK-SavannahThomasDataProjects
New Contributor II

Christopher thank you!! 

This worked perfectly.