How to use if-else in xls forms

how to use if-else in xls forms

also looking for same solution

··· On 21 May 2015 at 12:18, wrote:

how to use if-else in xls forms

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
**In sun set years education is not associated with standard of living and
medical care access; it is the the financial myosin and actin!!!

**** Don't give me fish, teach me how to fish

Kayoub K
0772656158 / 0703516660
PMTCT Data Manager
Mujhu Research Collaboration
Mulago Hosp

Lecturer
Kumi University

Hello there,

The if else end if is simple to use in XLSForm "if(${nodename}condition,value true,value false)

Example:

  • Assume we have variable Age as "S1_QAge" and this variable allows two answers 1 for Male and 2 for Female.
  • We add a calculate type variable name it "S1C1" and put the following line in calculation field
  • Formula is: if(${S1_QAge}=1,"Male","Female")
  • we add a note to check if the answer was 1 (Male) and display the message "You have selected Male as answer else "You have selected female as answer"

Note: and a note type variable e.g.: S1N1 and name and then for the label put the following:
"You have selected ${S1C1} as answer"

Hope this helps and if you need more help don't hesitate to write back

Jules R.

··· On Thursday, May 21, 2015 at 12:12:09 PM UTC+2, zahir...@gmail.com wrote: > how to use if-else in xls forms
1 Like

You can use conditional in XLS using relevant. Example. Link here
http://xlsform.org/

Note you can use it within grouping as well. See Skip.

Relevant

One great feature of XLSForm is the ability to skip a question or make an
additional question appear based on the response to a previous question.
Below is an example of how to do this by adding a relevant column for a
select_one question, using our pizza topping example from before:
survey typenamelabelrelevant select_one yes_nolikes_pizzaDo you like
pizza? select_multiple pizza_toppings or_otherfavorite_toppingFavorite
toppings${likes_pizza} = ‘yes’

In this example, the respondent is asked, “Do you like pizza?” If the
answer is yes, then the

··· On Thu, May 21, 2015 at 10:18 PM, wrote:

how to use if-else in xls forms

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Let the name and label of facility types is as follows:
name label
'1' Primary level care facilities
'2' Secondary level care facilities
'3' Tertiary level care facilities

if(${SQ2_006}='1', 'Primary level care facilities', if(${SQ2_006}='2',
'Secondary level care facilities', 'Tertiary level care facilities'))

··· On Thursday, May 21, 2015 at 1:12:09 PM UTC+3, zahir...@gmail.com wrote: > > how to use if-else in xls forms

Hi Jules,

I tried by using the same formula to calculate but it didn't work. Also, I
attached two jpg files for your review. Please help me to solve this
problem. I am looking forward to hearing from you soon. Thank you!

https://lh3.googleusercontent.com/-iX4tYllHjOc/V_tAz1VIPvI/AAAAAAAAMPA/MaVUpM7biWc2j_eK7Zy5DJ8brrtXhtRqwCLcB/s1600/If_function_odk.png

https://lh3.googleusercontent.com/-onkZoQMVmDw/V_tA295L0RI/AAAAAAAAMPE/JLg7sg9ivgIYF29qYs6Ja2-ev-_I-3kCACLcB/s1600/If_function_odk_error.png
Thuta

··· On Friday, May 22, 2015 at 5:52:01 AM UTC+6:30, jules rugwiro wrote: > > On Thursday, May 21, 2015 at 12:12:09 PM UTC+2, zahir...@gmail.com wrote: > > how to use if-else in xls forms > > Hello there, > > The if else end if id simple to use in XLSForm > "if(${nodename}condition,value true,value false) > > Example: > - Assume we have variable Age as "S1_QAge" and this variable allows two > answers 1 for Male and 2 for Female. > - We add a calculate type variable name it "S1C1" and put the following > line in calculation field > - Formula is: if(${S1_QAge}=1,"Male","Female") > - we add a note to check if the answer was 1 (Male) and display the > message "You have selected Male as answer else "You have selected female as > answer" > > Note: and a note type variable e.g.: S1N1 and name and then for the label > put the following: > "You have selected ${S1C1} as answer" > > Hope this helps and if you need more help don't hesitate to write back > > Jules R.

Hi Thuta,

The error "if requires 3 arguments" suggests that you've put a parenthesis
or comma in the wrong place. Since you are using Ona, perhaps you can ask
their support team to help?

Yaw

··· On Mon, Oct 10, 2016 at 9:19 AM, Thuta MaungMaung wrote:

Hi Jules,

I tried by using the same formula to calculate but it didn't work. Also, I
attached two jpg files for your review. Please help me to solve this
problem. I am looking forward to hearing from you soon. Thank you!

https://lh3.googleusercontent.com/-iX4tYllHjOc/V_tAz1VIPvI/AAAAAAAAMPA/MaVUpM7biWc2j_eK7Zy5DJ8brrtXhtRqwCLcB/s1600/If_function_odk.png

https://lh3.googleusercontent.com/-onkZoQMVmDw/V_tA295L0RI/AAAAAAAAMPE/JLg7sg9ivgIYF29qYs6Ja2-ev-_I-3kCACLcB/s1600/If_function_odk_error.png
Thuta

On Friday, May 22, 2015 at 5:52:01 AM UTC+6:30, jules rugwiro wrote:

On Thursday, May 21, 2015 at 12:12:09 PM UTC+2, zahir...@gmail.com wrote:

how to use if-else in xls forms

Hello there,

The if else end if id simple to use in XLSForm
"if(${nodename}condition,value true,value false)

Example:

  • Assume we have variable Age as "S1_QAge" and this variable allows two
    answers 1 for Male and 2 for Female.
  • We add a calculate type variable name it "S1C1" and put the following
    line in calculation field
  • Formula is: if(${S1_QAge}=1,"Male","Female")
  • we add a note to check if the answer was 1 (Male) and display the
    message "You have selected Male as answer else "You have selected female as
    answer"

Note: and a note type variable e.g.: S1N1 and name and then for the label
put the following:
"You have selected ${S1C1} as answer"

Hope this helps and if you need more help don't hesitate to write back

Jules R.

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hello Thuta,

Apologies for a very delayed rep, i would suspect the following two things
for the error:

  • What is the data type for B_Q2
  • Why are you enclosing the condition into quotes? eg.: if(${B_Q2}='1',2,0)
    try without quotes like if(${B_Q2}=1,2,0) i can;t really be sure since
    unless if you let me know the data type of the question in reference "B_Q2"

Let me know how it goes if not too late already

Best,
JR

··· On Mon, Oct 10, 2016 at 12:28 PM, Yaw Anokwa wrote:

Hi Thuta,

The error "if requires 3 arguments" suggests that you've put a parenthesis
or comma in the wrong place. Since you are using Ona, perhaps you can ask
their support team to help?

Yaw

On Mon, Oct 10, 2016 at 9:19 AM, Thuta MaungMaung thutamgmg@gmail.com wrote:

Hi Jules,

I tried by using the same formula to calculate but it didn't work. Also,
I attached two jpg files for your review. Please help me to solve this
problem. I am looking forward to hearing from you soon. Thank you!

https://lh3.googleusercontent.com/-iX4tYllHjOc/V_tAz1VIPvI/AAAAAAAAMPA/MaVUpM7biWc2j_eK7Zy5DJ8brrtXhtRqwCLcB/s1600/If_function_odk.png

https://lh3.googleusercontent.com/-onkZoQMVmDw/V_tA295L0RI/AAAAAAAAMPE/JLg7sg9ivgIYF29qYs6Ja2-ev-_I-3kCACLcB/s1600/If_function_odk_error.png
Thuta

On Friday, May 22, 2015 at 5:52:01 AM UTC+6:30, jules rugwiro wrote:

On Thursday, May 21, 2015 at 12:12:09 PM UTC+2, zahir...@gmail.com wrote:

how to use if-else in xls forms

Hello there,

The if else end if id simple to use in XLSForm
"if(${nodename}condition,value true,value false)

Example:

  • Assume we have variable Age as "S1_QAge" and this variable allows two
    answers 1 for Male and 2 for Female.
  • We add a calculate type variable name it "S1C1" and put the following
    line in calculation field
  • Formula is: if(${S1_QAge}=1,"Male","Female")
  • we add a note to check if the answer was 1 (Male) and display the
    message "You have selected Male as answer else "You have selected female as
    answer"

Note: and a note type variable e.g.: S1N1 and name and then for the
label put the following:
"You have selected ${S1C1} as answer"

Hope this helps and if you need more help don't hesitate to write back

Jules R.

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to a topic in the
Google Groups "ODK Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/opendatakit/Q77Rz3MrKkU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I have trouble using the if() function.
I would like to show a certain message based on how participants rated certain questions (dependent on the maximimus sum of certain questions compared to the sum of certain other questions). For example 5 questions each could measure certain personality traits such as opennes, extroversion, agreeableness and so on. Dependent on which of these constructs a person scores the highest (sum of questions measuring one trait compared to another sum of another trait) I want to show them a certain message. The sum of each trait I calculate with ${open1} + ${open2} + ${open3} + ${open4} + ${open5}.
I would basically have to use the if()-function with several else conditions function to show participants a certain note depending on a previous sum-calculation of openness ${o} vs. extroversion ${e} vs. agreeableness ${a}.
My initiall idea was to stack several if functions into each other:

if(${o} > ${e} and ${o} > ${a}, '1' , if{${e} > ${o} and ${e} > ${a}, '2', if{${a} > ${o} and ${a} > ${e}, '3', '4' }}}

Depending on the outcome {e.g. '1'.'2','3'.'4') I would then use the relevant column to display the message.

Here is the example:

This does however not work. Is there another way or function to solve this?

Hi @colonus

first of all, there is a mistake in your form: you have 4 notes named show_high (the name must be unique).

The second thing is that your if statement should rather look like:
if((${a} > ${b} and ${a} > ${c}), '1', if((${b} > ${a} and ${b} > ${c}), '2', if((${c} > ${a} and ${c} > ${b}), '3', '4')))

Please let us know if it solves your problem.

3 Likes

Your calculation is largely correct, except that you have to remember that if is a function, therefore its (three) parameters are always surrounded by if(...). Other than your first if above, both your nested ifs have if{...}, which is syntactically incorrect. @Grzesiek2010 response shows what all the correct parentheses should look like.

1 Like

oh thanks! sorry, should have figured that myself. It worked!

1 Like

No worries! Don't hesitate to ask if you have a problem.

2 Likes

Hello Zahirquazi,

If-else is simple. I have used it severally and I will show you how. It's used with 'calculate' which means the if-else statement will be in the calculation column as shown in the example below:

if(${q7}=2, 'choice one ','choise two for else')

Thank you, This worked for me too