Calculate Field - Count

697
4
10-23-2023 09:07 AM
RutledgeNicholas
New Contributor III

I have an inventory of cases with radios in them (assigned). The radios are assigned to a specific case in our cache radio inventory. Is the a way in the case inventory to calculate how many radios are assigned to a specific case?

0 Kudos
4 Replies
abureaux
MVP Regular Contributor

Not quite sure how you have this set-up. So I will give a couple potential solutions:

  • count(${repeat_name}) counts the items in a repeat.
  • sum(${thing_in_repeat}) sums a field within a repeat. Depending on the scenario, I combine this with a binary calculate located within a repeat (e.g., if(selected(${question1},'apple'),1,0)) so, for example, I will know how many selections of "apple" were made within a repeat.

May help if you upload a screen cap or even the XLSX. The solution could be above, or you may need something else entirely.

0 Kudos
RutledgeNicholas
New Contributor III

@abureaux Thank you for the reply. I may need to explain a little bit more. I have a two separate feature layers in AGOL. One is the feature table of Cache Radio Cases and another feature layer which is individual radios which will be assigned to one of the cache radio cases. I am pulling the case radio caseID as a dropdown menu from using an autocomplete search string in the appearance column to populate the available cases to choose from when assigned the radio to a specific case. 

What I am wanting to do now is count the number of radios assigned to each case and have that auto calculate the qty of radio's assigned in the Cache Radio Case feature layer. Here are the two survey123 XLSForms that I have for these two feature layers along with a flow chart that sort of explains my end result goal.

The ultimate goal will be for checking cases out to agencies and being able to log the radios associated with that case at that time and then also a second goal to also be able to track the individuals that the radios are checks out too.

This might be too much information, but I wanted to give little background as to what I'm working towards.

Thank you

0 Kudos
DougBrowning
MVP Esteemed Contributor

If it is two layers I would look at Data Expressions in Dashboards.  That way you can check both layers and display from there.  Sounds like you want a current status type thing.

abureaux
MVP Regular Contributor

Thank you. That really helps us get an idea of what you are trying to achieve.

As Doug Browning mentioned, you could potentially achieve this outside of Survey123.

If this solution needs to be within S123 (i.e., visible while the form is being filled in), then perhaps JS would work. You could query the second database using the CaseID / AssignedCaseID field(s), then use JS to count the number of items returned since it is an array. Something like this.

The first thing I thought of was "it would be nice to see details on the radios inside the form", but that would require linking of databases, and would further require use of the Inbox feature as that is the only way to populate a repeat (which this data would be). And that seems like it is deviating too much from your current set-up. I thought I would at least mention the idea though since I felt it was a natural suggestion.

0 Kudos