Select to view content in your preferred language

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

674
4
Jump to solution
02-23-2024 12:22 PM
AK-SavannahThomasDataProjects
Emerging Contributor

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

4 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
Emerging Contributor

Christopher thank you!! 

This worked perfectly. 

LJackson29
Frequent Contributor

@ChristopherCounsell I am trying to repeat this workflow and cannot get it to work. I did have a join working when I originally completed my form, but it has been broken for at least 6 months. I am not sure if there was an update that caused it to break or what.

I have confirmed that my concatenate calculation works, and believe it is something in step 2 above, as when I unhide the Phase_summary field (see snapshot) nothing appears - it is just an editable box.

Do you have any suggestions of where I am going wrong? Thanks in advance.

LJackson29_0-1738254781674.png

 

LJackson29_1-1738254865985.png

 

0 Kudos
ChristopherCounsell
MVP Regular Contributor

I would recommend making a new post and providing your XLSForm. Unanswered posts get more attention. Feel free to tag me or other MVPs.

Your circumstances sound different. Notably the formatting and you're using the web app. Can't provide any insight without the xlsform to be honest.

0 Kudos