Finding maximum occurrence within a loop

Hello,

Have a new question.

I am creating a form where a number of teams fill a few details that include them rating other teams as rank1 or 2. At the end of the loop, I would like to calculate which team has had the most number of occurances at and then at 2. Any ideas how we can do that?

inquilab-Learn-and-give-ideas-final.xlsx (20.7 KB)

What have you tried so far? In particular, have you tried some of the operators and functions at https://docs.opendatakit.org/form-operators-functions

1 Like

FYI take a look at the max() and sum() functions. You may be able to exploit them for your intended purpose, depending on how exactly you capture these team rankings.

1 Like

Hello Prasanna,

I am assuming the rankings you mention are in lines 58 (best_idea_in_class) and 59 (second_best_idea_in_class).

In order to achive what you mention, I would create several variables with "calculate" before the end of the repeat group, where each team would have 2 variables named "first_TeamX" and "second_TeamX" (X being a letter from A to O for what I can see in your file; in total 30 variables (15x2)).

This would result in the following:


+-----------+--------------+---------------------------------------------------+
|   type    |     name     |                     calculation                   |
+-----------+--------------+---------------------------------------------------+
| calculate | first_TeamX  | if(${best_idea_in_class}='Team_X','1','0')        |
| calculate | second_TeamX | if(${second_best_idea_in_class}='Team_X','1','0') |
| calculate | first_TeamY  | if(${best_idea_in_class}='Team_Y','1','0')        |
| calculate | second_TeamY | if(${second_best_idea_in_class}='Team_Y','1','0') |
+-----------+--------------+---------------------------------------------------+

Then, after the end of the repeat you add this:


+-----------+------------------+------------------------------+
|   type    |       name       |         calculation          |
+-----------+------------------+------------------------------+
| calculate | all_first_TeamX  | number(sum(${first_TeamX}))  |
| calculate | all_second_TeamX | number(sum(${second_TeamX})) |
| calculate | all_first_TeamY  | number(sum(${first_TeamY}))  |
| calculate | all_second_TeamY | number(sum(${second_TeamY})) |
+-----------+------------------+------------------------------+

Here you can use a variable "note" to show the overall results for all teams and/or max() to know which is the maximum number of votes a single team received in each category.

The other alternative I can think about is using several if(), and I am not sure how a tie would be handled.

Hope it helps.

2 Likes

The way I have set up the ranking is that the person just to choose the team name from a drop down.

But this currently is happening over a loop function.

So

Team A
Details
Details
Details
Ranking Other teams - 1 - Dropdown with a list of all teams
Ranking Other teams - 2 - Dropdown with a list of all teams

Entries for Team B Begins
...

I thought both Max and Sum are number driven expressions. It was after my confusions with the numbers that I finally made it where they choose the team. That way I can at least look at the output google sheets and figure the team that got ranked most. Yet it would be great if I could find most chosen response from a drop down in a repeated set within a loop.

This is a great idea. I will most definitely try this out. If I find an alternative, I will keep you posted as well.

Thanks again. Also, welcome back, the thread shows you are posting after 6 months :). Thank you for offering that time to this question here.

So before the version of the xls I have posted here, I tried with Sum, Count, Max but clearly not writing the formula enough. I had each team being given a rank number, tried the rank function widget and choosing from a radio button. In all the cases, I was still not able to find a proper way to say that in all the loops filled so far, Team A was the most chosen response to question on best ideas, Team B was most chosen to question on second best idea.

Hi again,

I somehow seem to make some calculation error within the loops and I am.not sure what am I doing wrong here. The screen now does not allow me.to move past this stage. Any help.would be highly appreciated !

Also, when I run the script , all things that are mentioned as xyz ends up be italicised. Like in this case, if I run a calculation that says all_first_rank ... It turns into an italicized version of the word first. Same thing w the school name. Any work around suggested?

inquilab-Learn-and-give-ideas-final.xlsx (26.2 KB)

calculations start from row 78 and run thru row 180, but I think the first one itself should be able to show up the issue.

Try placing the rows 88 to 132 inside the repeat. I think that should solve the problem (or at least one of them).

This is best explained in the Repeat Recipes section of the docs.

2 Likes

Bless you! I am going to try this and I will keep you posted :slight_smile:

Unfortunately didn't work. Any idea what I maybe doing wrong?

Try with the XLSForm Offline converter (although I don't think that should make a difference).

I could only find one other post where a similar error was reported.

It seems like it happens when a group only has calculate values in it. Check if that is the case for your group ${Final_Notes}

Edit: There is another post about it

Thank you, it does have only calculations in it. Should I take the group off and try?

I just did this, and now it says important column headers missing. I checked for all of them and they are all there. This is beyond frustrating now :slight_smile: .

Just when you think you have learnt a lot, the system tells you that aren't even a 3 steps in !

It worked. Thanks a lot !! :slight_smile: