I am new to excel syntax. I learned that the if statement should be formatted if(condition, a, b) as in the Esri docs screenshotted below. This is for the relevant field of a question.
The problem is, it is unclear to me what this 'yes', 'no' is. Does this refer to my particular choice names? or is it a global variable? I want the if statement to be: if(condition, show the question, don't show the question).
E.g. if my questions were about consent in the example screenshot, would I have:
if(selected(${Q1_consent}, 'Yes, I consent') and selected(${Q2_incity}, 'Yes, I live in the city'), 'Yes, I consent', 'No, I do not consent')
...based on what I have in my choice tab? or would it be:
if(selected(${Q1_consent}, 'Yes, I consent') and selected(${Q2_incity}, 'Yes, I live in the city'), 'yes', 'no')
'yes' is in this example the result for if the condition is true and 'no' the result if the condition is false.
For the correct if statement it is relevant what you have in the name column of your choice option. If the label says 'Yes, I consent' but the name says only 'yes', then I would assume you would like something like
if(selected(${Q1_consent}, 'yes') and selected(${Q2_incity}, 'yes'), 'Yes, I consent', 'No, I do not consent')
Hi @Nicole_Ueberschär Nicole, thank you. So it's in your example:
if(selected(${Q1}, 'choice_name') and selected(${Q2}, 'choice_name'), 'label_name', 'label_name')?
The output of the if statement is a simple string so you could put anything there. If you would like to use the labels of the selected options then you could use jr:choice-name(${Q1}, '${Q1}').
I think you are getting lost in what an if statement is and not necessarily what you need. It sounds to me like you want a field to be relevant if ${Q1_consent} is 'Yes, I consent' and ${Q2_incity} is 'Yes, I live in the city'.
If that is the case and assuming that the actual choice names are 'yes', you would just need to add this in the relevant field: ${Q!_consent}='yes' and ${Q2}='yes'
How the relevant column works is that if what you put in it evaluates to true, then the field is 'relevant' and displayed, if it is not true, then it is not displayed.
You were exactly right. In the end I thought I needed if statements as I had multiple criteria to run through.
Ultimately I needed: (${Q1}='yes' and ${Q2}='yes_city') or (${Q1}='yes' and ${Q2}='no_not_incity' and ${consent_gdpr}='yes_gdpr').