Auto calculate the total

1. What is the problem? Be very detailed.

2. What app or server are you using and on what device and operating system? Include version numbers.

3. What you have you tried to fix the problem?

4. What steps can we take to reproduce the problem?

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.

Help am new to ODK am trying to make am trying to make the total auto calculate the sum of male and female.please can some one show me how the calculations are done

TestSum.xlsx (11.4 KB)

@bob check the example in the xlsform attached.

Ok I found out a possible issue. With the form attached before.
Having the calculation shown on the same page doesn't really work (it works in enketo).
You could force to go to the end and save the form and then the value total will be saved.
To see the value of the calculation then the sum must be placed outside the group.
Maybe a bug of collect? @Grzesiek2010

TestSum2.xlsx (11.4 KB)

I think you can do it using a note with the fieldlist:

in your spreadsheet line 25 use the following

change Type from integer to note
change the label from "Total" to "Total ${total_calc}" (my quotation marks!)

This worked for me on a different form that I had been scratching my head over, wanting to see a calculation on screen... When you upload the data there will be a column for "total_calc", so you don't need to have the integer as well

Hope this helps.

you are right @seewhy,

as I wrote the calculation itself happens, and the note is a workaround, but I think the integer field should work as well, and maybe could be fixed.

Apologies - I was responding to this statement - I understand it is a workaround, but does that mean that the integer type needs to be fixed? Perhaps it is a similar issue to cascading selects and field-list? There is a warning about this in the docs, and you have highlighted that in your answer:
https://docs.opendatakit.org/form-question-types/#grouping-multiple-widgets-on-the-same-screen
That's why I thought a workaround might be helpful, as it could mean major refactoring (not that I would be averse to that change!).

You would probably also need to set an integer to read-only, or perhaps find some confusing data if someone changed the value (it might recalculate on save?). It would also result in an additional column in the dataset that has the same value as the calculate one (using a note still adds a column to the uploaded data, but it is blank).

Not trying to be critical of your answer, but I was thinking of it from a data management perspective as well as functionality in the field - being Stupid, I like to Keep It Simple :slight_smile:

Hi @seewhy,

I think the documentation is not yet fully updated
In ODK Collect v1.22.0
Relevance, constraints, and calculates now work on the same screen

That's why I thought to a bug.

It was like this in my original test form.

Hi @bob

This issue was already discussed in a different topic.

@seewhy reply is correct.
You are performing a calculation in row 25 (${total_cal}).
The calculation in row 26 is redundant per se, and should be removed (you cannot enter an integer and perform the calculation at the same time).

Depending on what you want to achieve, you would need to edit row 26.
a) if for some reason you want to validate the total entered by the user, you need to enter .=${total_calc} in the constraint field
b) if you want to display to the user the total (i.e. automatic calculation) you would write ${total_calc} in the label field.

I hope this helps!

Best,
Andrea

What you say is not totally correct.
It doesn't work inside the group, but it works if outside (test it before saying that is not possible).
I added

Correct.
But the integer in readonly it's nicely rendered :smiley: (See the second xls I uploaded)

Yes it seems like a bug, I'll report it. Thanks!