Adding values of more than 2 variables in xlsform

Need Help!!!
In my xlsform I have 11 variables collecting different types of participants numbers. Now I need a calculated value with sum of all those values from 11 variables.
Working file link is here. Please see row number 25.

Hello @prosonno_hasda, welcome to the community!

I think you are getting a NaN value? Is that correct?

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 changing your calculation to this should solve your issue:

coalesce(${adolescent_girls}, 0)+coalesce(${adolescent_girls_mm},0)+...

2 Likes

Thank you very much!

2 Likes

@hakan_cetinkaya, @prosonno_hasda :clap: :heart: :partying_face:

1 Like