Calculate the sum from select multiple question

Hello Team,

Kindly assist me, I am trying to calculate a total value depending on the species of fish chosen from the group and the weight and value-filled.
Right now it’s not populating.
aPsmJkcegnRGTVvBmfTnZH.xlsx (11.2 KB)

Hi @zachzach13 and welcome to the community!

Can you share the calculation process with the community? Preferably with screenshots if you can.

1 Like

aPsmJkcegnRGTVvBmfTnZH.xlsx (11.2 KB)

@zachzach13 can you also explain the part where you are having trouble with?

1 Like

Thank you for the quick feedback,

  1. Before i included the select multiple (row 32) i could get the total at row 56 and 58…but when i included the select multiple (row 32) now the sum doesn’t populate.

@zachzach13,

Do you get a NaN value?

1 Like

Not after I added the choose multiple

Can you explain this a little further?

1 Like

okay let me try and make it simple…
How can i include a sum at the end of the form depending on SPECIES CAUGHT?

Hi @zachzach13

If DID YOU CATCH FISH TODAY? question has been answered YES, your SUM note displays NaN

That is because In the ODK Form Logic, unanswered number questions are nil. That is, they have no value. When a variable referencing an empty value is used in a math operator or function, it is treated as Not a Number (NaN). The empty value will not be converted to zero. The result of a calculation including NaN will also be NaN, which may not be the behavior you want or expect.

To convert empty values to zero, you can use either the coalesce() function or the if() function.

coalesce(${potentially_empty_value}, 0)
if(${potentially_empty_value}=“”, 0, ${potentially_empty_value})

In your case, you have possible unanswered integer questions depending on your multiple choice question.

So changing your calculate Total_Weight question to:
coalesce(${NPW}, 0)+coalesce(${DW}+...

would solve your issue.

1 Like

Wow, thanks a bunch. let me read more about it and make the edits.

1 Like

Works like a charm. I appreciate you brother. Thank you.

2 Likes

I have just thought of a different scenario. What would I do 8n the same case if the species were very many. Like 300 marine species?