Sum of differents variables getting NAn

Hello guys, im trying to get my forms ready but now i have a problem that i do not understand, is easy im just calling some variables and suming them all but is giving me Nan as an answer for Total(l/s): ${calculationcaptaciones} here is a google docs url to the excel form because im new i cant upload. Thanks and sorry for my english, and im so sorry because the form is in spanish.
https://docs.google.com/spreadsheets/d/13I3nI8O-nO5jTIu55UiRxTd0xfiy2lx_/edit?usp=sharing&ouid=112336822485279917052&rtpof=true&sd=true

Hi @christianmaa and welcome to the community!

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 need to put coalesce before every potential empty integer value. Not just before whole calculation.

1 Like

@christianmaa, you should be able to learn more about the coalesce function through our community posts that have been discussed previously here.

1 Like