Calculating a value from NaN

To display the output of the calculator I created a Note question and add ${calculation} but is sowing NaN instead of value

Hello,
NaN means Not a Number. So there is at least one element in your calculation which evaluates to ‘’.
Use coalesce( ) to control this effect. See https://getodk.github.io/xforms-spec/#fn:coalesce

2 Likes

Hi @rahul_521,

Maybe you could also have a look at a simple workaround discussed previously using coalesce:

For the gory details see https://docs.getodk.org/form-logic/#empty-values-in-math. Most likely you are including a non-mandatory (and unanswered…) question result in the calculation. Unfortunately, unanswered/empty inputs are not treated as zero (!), resulting in a NaN calculation result. As @wroos states, when including non-mandatory responses in a calculation you must add a coalesce() to your calculation to explicitly convert any null values to 0.

3 Likes