Form error for calculation

Hello,

I have this error:

  • FormLogicError: Could not evaluate: if( /model/instance[1]/data/group_ll9ke29/AHIV =’‘0’’,’‘0’’,if( /model/instance[1]/data/group_ll9ke29/AHIV =’‘1’’,’‘0’’,if( /model/instance[1]/data/group_ll9ke29/AHIV =’‘2’’,’‘5’’,if( /model/instance[1]/data/group_ll9ke29/AHIV =’‘3’’,‘10’if( /model/instance[1]/data/group_ll9ke29/AHIV =’‘4’’,’‘15’’,’ ‘))), message: Weird args (should be separated by commas):[{“t”:“bool”,“v”:true},{“t”:“num”,“str”:“4”,“v”:4},{“t”:“str”,“quote”:"’",“v”:""},",",{“t”:“str”,“quote”:"’",“v”:""},{“t”:“num”,“str”:“15”,“v”:15},{“t”:“str”,“quote”:"’",“v”:""},",",{“t”:“str”,“quote”:"’",“v”:" "}]

This is my question below:

(INDICATE THE APPROPRIATE RESPONSE BETWEEN 0 AND 4 FOR EACH SERVICE)
0=Do not provide service
1= Less than 500 client visits
2= Up to 500 client visits
3= 501 – 2000 client visits
4= 2000+ client visits

A. HIV testing ……………………[ ]
B. ART…………………………….[ ]
C. Voluntary Male Circumcision……………….….[ ]
D. Cervical Cancer Screening ….[ ]
E. Family Planning………………[ ]
F. HIV Pre-Exposure Prophylaxis (PrEP) …………………………[ ]
G. Antenatal services……….…. [ ]
H. Labor and Delivery Services…[ ]
I. Childhood immunizations and growth monitoring……………[ ]
J. other ___________________[ ]
(Specify)

How do I go about the calculation to make a score?

Hello @Faith,

Can you provide a screenshot of the calculation column you are using? I think you are giving scores with if statements and something is not right with the statement.

1 Like

Here is the screen shot

Hi @Faith,

The if statements work like this in KoBo:

if( ${Question} = ‘Choice’, THEN, ELSE)

Notice there are no quotation marks ( " ) in the statement. There is only Apostrophe ( ' ) for specifying the choice of your question.

I think you are using these scores you created with if to calculate a decimal equation.

So trying to write your statements like this should solve your issue:

if(${AHIV}= ‘0’, 0, if(${AHIV}= ‘1’, 0, if(${AHIV}= ‘2’, 5, if(${AHIV}= ‘3’, 10, 15))))
Notice that, i skipped last if statement because there is no other answer can be given
On second look I saw you didn’t make this question mandatory so above statement should be re-written for the blank questions

Feel free to ask if you need further help, hope this helps.
Best,

1 Like

@hakan_cetinkaya
Thanks a lot I much appreciate. This is very helpful and it has worked, I struggled the whole morning.
Just for my learning purposes, for option number 4, no need of highlighting it as: (${AHIV}= 4’, 15?

2 Likes

@Faith hi,

I make the 15 as an else option, as in if nothing prior to that has been selected, but i saw you didn’t make the question mandatory, meaning someone might skip an answer to that question, if so you should consider giving a score for blank questions.

1 Like

@hakan_cetinkaya :clap: :heart:

1 Like

@hakan_cetinkaya
In this case I want to make it mandatory, I want the user to fill in all options, such that were they are not providing a service, they input 0.
Hence does the statement change to this below:

if(${AHIV}= ‘0’, 0, if(${AHIV}= ‘1’, 0, if(${AHIV}= ‘2’, 5, if(${AHIV}= ‘3’, 10,if(${AHIV}= ‘4’, 15))))

@hakan_cetinkaya kindly confirm my previous post

if(${AHIV}= ‘0’, 0, if(${AHIV}= ‘1’, 0, if(${AHIV}= ‘2’, 5, if(${AHIV}= ‘3’, 10,if(${AHIV}= ‘4’, 15, 0)))))

should work.

1 Like

Much appreciated.

1 Like

Do you have any soft copy user guide for guidance on such calculations?

Hi @Faith,

There is an article in Help Center:
https://support.kobotoolbox.org/advanced_calculate.html

Also there is a document in here for Form Operators and Functions:
https://docs.getodk.org/form-operators-functions/#functions

Hope these will help you.

1 Like

@hakan_cetinkaya Thanks I guess this will help.

2 Likes

@hakan_cetinkaya

Hi Hakan,

I have struggled with this form for total calculation.I need help and the link is below

https://kf.kobotoolbox.org/#/forms/aBQEt5Kv5SXpz3zcHwbQMJ/edit

For the last role total score, and the calculation on question 13 which is giving an error.

sample excel output is attached
excel output.xlsx (15.1 KB)

Hi @Faith,

I can’t access to your forms through KoBo :slight_smile: I’m just someone who is part of the community not the Core Team.

If you can download your form as .xls file and share with me I’ll be happy to look further. To do that, you can click on your Projects and when you click the More actions button, you can download your form in xls format.

For more information you can look here:
https://support.kobotoolbox.org/kobotoolbox_interface.html#project-actions

@hakan_cetinkaya I have created a new question as this topic is showing solved