Calculation error

I want to calculate the respondent asset index (total number of assets in the household). Therefore I have developed questions like the number of mobile, number of laptops, and number of other assets in household. And then use the formula “+” to calculate the asset index. But the problem is that the formula only works when all assets from the choice list are selected other wise it provides blank data. In reality, it is very common that a household does not have all the assets from the choice list. How to solve the issue

Hi @taslimashormi and welcome to the community!

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})

2 Likes

thank you so much

2 Likes