Calculation - How to factor in questions with relevance expressions not appearing

Hello,

I am building a form where I need to calculate an integer by adding up integers entered in response to other questions. Some of these are subject to relevance expressions and might or might not appear depending on the options selected in previous questions.

Unfortunately, when they remain hidden and thus no integer is inserted, the following calculate function does not seem to be working. Therefore, I was wondering whether there is a way to ensure the calculate function automatically considers as zero all the integers of the questions with relevance expressions that do not appear.

Many thanks,

Francesco

@nrc_me1, maybe you will need to share your issue with a screenshot so that the community should also be able to understand your issue pictorially.

Hi @nrc_me1
This issue has been previously discussed in some of the following topics represented in this search. I would also recommend that you follow this approach and it should solve your issue

Stephane

1 Like

Hi @stephanealoo,

Thanks a lot for your reply and for pointing me in the right direction.

I tried to fix it by using the IF function, but it does not seem to be working when the sum calculation includes addends that are null as a result of a skip logic (Relevant). It only works when the question is not conditional and I just leave the field blank.

Any help on this will be highly appreciated.

Francesco

Hello @nrc_me1,
You might need to use the coalesce function and the sum calculation. See https://getodk.github.io/xforms-spec/#fn:coalesce.
Maybe you also need to explicitly cast your numbers to string with https://getodk.github.io/xforms-spec/#fn:string.

Did you already go through the links provided by @stephanealoo above?

2 Likes