Calculation from a mutiple choice question

Hi everyone,

Sorry in advance if the subject have already been discussed, but I did not
manage to find an answer here.

I'm new on ODK and I have a trouble to calculate previous answer from a
multiple choices question.

I have a question with 5 different multiple choices of land type (type 1,
type 2...) followed with a relevant decimal question if selected. I want to
calculate at the end the total land owned from the decimal question. It
seems it work only if the interviewee answer all the choices and therefore
all the decimal questions. If he only selects 2 choices, the empty cell
must block the calculation.

Can you confirm me this? Does someone have an alternative solution?

I have attached a file in order to be clearer.

Charlotte

Calculate with multiple choices.xlsx (9.37 KB)

Hi Charlotte,

The problem is if any of the values is NOT selected, it returns a NULL
which you cant use in the calculation abd thats why the calculation fails.
One option is first to test that the value is selcted and then use it in
the calculation. You can use something like:
coalesce(\${type_1},0) + coalesce(\${type_2},0) + coalesce(\${type_3},0) +
coalesce(\${type_4},0) + coalesce(\${type_5},0)

The coalesce function is useful for choosing which of two values to
return. It will return the non-null/empty value. If both are not null,
will return the first argument.
I have havent tested that but that should work.
You could also use an if statement that checks with a value is selected
before using it in the calculation.

Kind regards,

··· On Wednesday, 10 August 2016 07:59:40 UTC+2, Charlotte wrote: > > Hi everyone, > > Sorry in advance if the subject have already been discussed, but I did not > manage to find an answer here. > > I'm new on ODK and I have a trouble to calculate previous answer from a > multiple choices question. > > I have a question with 5 different multiple choices of land type (type 1, > type 2...) followed with a relevant decimal question if selected. I want to > calculate at the end the total land owned from the decimal question. It > seems it work only if the interviewee answer all the choices and therefore > all the decimal questions. If he only selects 2 choices, the empty cell > must block the calculation. > > Can you confirm me this? Does someone have an alternative solution? > > I have attached a file in order to be clearer. > > Many thanks for your answers, > Charlotte > > >

Hi Sam

coalesce function and its working perfectly!

Many thanks
Kind regards

Charlotte

··· Le mercredi 10 août 2016 19:22:20 UTC+6:30, Sam Phiri a écrit : > > Hi Charlotte, > > The problem is if any of the values is NOT selected, it returns a NULL > which you cant use in the calculation abd thats why the calculation fails. > One option is first to test that the value is selcted and then use it in > the calculation. You can use something like: > *coalesce(\${type_1},0) + coalesce(\${type_2},0) + coalesce(\${type_3},0) + > coalesce(\${type_4},0) + coalesce(\${type_5},0)* > The coalesce function is useful for choosing which of two values to > return. It will return the non-null/empty value. If both are not null, > will return the first argument. > I have havent tested that but that should work. > You could also use an if statement that checks with a value is selected > before using it in the calculation. > > Kind regards, > > On Wednesday, 10 August 2016 07:59:40 UTC+2, Charlotte wrote: >> >> Hi everyone, >> >> Sorry in advance if the subject have already been discussed, but I did >> not manage to find an answer here. >> >> I'm new on ODK and I have a trouble to calculate previous answer from a >> multiple choices question. >> >> I have a question with 5 different multiple choices of land type (type 1, >> type 2...) followed with a relevant decimal question if selected. I want to >> calculate at the end the total land owned from the decimal question. It >> seems it work only if the interviewee answer all the choices and therefore >> all the decimal questions. If he only selects 2 choices, the empty cell >> must block the calculation. >> >> Can you confirm me this? Does someone have an alternative solution? >> >> I have attached a file in order to be clearer. >> >> Many thanks for your answers, >> Charlotte >> >> >>