Counting "unique" selections across repeats

6197
13
04-10-2019 04:33 PM
KarenTuerk2
New Contributor

OK, here's the deal. I am trying to create a field that will count the total number of plant species observed in a plant survey. The survey has 100 subplots (repeating form 1-100). Each subplot repeat and has a nested repeat that asks observers to choose all the plant species found in that subplot. I can use count(${plant_sp}) to get the total number of plant species selected throughout the survey, but I want to count only the number of unique species selected in the survey. This is to find the species richness of the site.

For example, if there is a daisy, coneflower, and hawkweed in every subplot, I need the count to be 3 and not 300. There are literally hundreds of possible choices for each subplot.

Is there a way to pull the number of unique codes from a concatenated list of all the species codes #from a
join(' ,' ${plant_sp}) perhaps?

Thoughts?

Thanks!

Karen

Tags (2)
0 Kudos
13 Replies
DougBrowning
MVP Esteemed Contributor

Have you got it to work as a constraint?  I can get a message to show like the example but when I try to use it as a constraint no go. 

If I add to the note relevant it shows the note but when I add it to the constraint it still lets me keep going.

pulldata('@javascript', 'repeats.js', 'distinctCheck', ${SpeciesFound})  tried with and without the not()

If I add it to a join list constraint then it will not let me add anything.

I want it so that they cannot go on in the repeat with a dupe.  That is what my way did.  This gives a warning but still lets them do it.

Not sure what I am missing.

Thanks

0 Kudos
RoryMcPherson
New Contributor III

The way I have it set up is using the distinct pulldata() function for species in a calculation for each associated plant type, which there aren't too many categories for. These are essentially just Boolean returns. I've then got a hidden species_check question using an if() calculation assessing if all the distinct checks return true. If any return false, as in a duplicate species has been selected for that plant type, the species_check returns a false; likewise, if all checks return true the check passes and returns true. I'm using this true/false return as a constraint on my select_one species in the repeat. This works for me as it triggers the constraint if they select the same species and then try to pass the repeat record.

Make sense? Hope that helps.

0 Kudos
JosephBusalacchi
New Contributor

Good Day Sir,

Any chance you can share the final spreadsheet showing the code you used to link all this together?  I am working on a very similar project and would like to either limit a species from being entered twice or show a warning message if it is attempted.  I get the basic portion of the Java code to work, it just shows the message all the time and I am not having any success in only showing the message when it is necessary.

Best,

Joey

0 Kudos
DougBrowning
MVP Esteemed Contributor

I never got javascript to work how I want but my other way posted here https://community.esri.com/message/932144-re-can-i-prevent-a-value-from-being-submitted-multiple-tim...

Does work for species.

Hope that helps.

0 Kudos