How to refer to answers from previous questions in labels?

I would like to ask if there's a way to refer answers from previous questions, and put it on labels for another questions.

Currently I have this question
select_one F3 | F3 | Which restaurant did you visit?

  1. Restaurant A
  2. Restaurant B
  3. Others

If they pick Others, I have set up a follow-up question in this way
text | F3_OT | Which other restaurant?

And based on that answer, I would like to form the other questions in this similar format, for example:
"Food at (restaurant name) is delicious"

I heard that I can write it as "Food at ${F3} is delicious", but since F3 has the Others option that leads to a text answer, how can I accommodate it so it can still function like this?

Thank you for your help!

You can use a calculate variable with an if condition to generate the relevant text (based on the select), and then reference it in your label.

I'm not entirely sure on how to apply calculation here, i tried "Food at if(${F3}='3',${F3_OT},${F3}) is delicious" but if I pick 1 at F3 it simply returns "Food at if(1='3',,1) is delicious", what was my mistake here? Do I need to add a separate questions to show the calculation first, then use that as reference in the other question labels?

You need to add a calculate type variable (e.g. calcVar) with the if clause as calculation. And in the note (or another label) you reference this calculate variable (e.g. ${calcVar} ).

Ciao @ihsanhutapea,

You are on the right path, below is a breakdown to achieve the desired labeling

  • With a regular select_one, you could use jr:choice-name() the label of selected value, however, since you have other, as @wroos suggested, you will need to combine the function above with an if() condition to check if restaurant was one of predefined list or other, if the latter, then we get the text from other_field
  • Since these functions cannot be used as inline (label or note) values, you will need a dedicated calculate field to hold the label, and that same calculate is what you will reference in labels and or notes
  • if(selected(${q1_restaurant},'88'), ${q1_restaurant_oth}, jr:choice-name(${q1_restaurant},'${q1_restaurant}'))

Try this sample form for an actual demo and sample xlsform

Hoping this helps (read more on jr:choice-name())

Jules R

This should be in your calculate;

if(${F3} = '3', ${F3_OT}, jr:choice-name(${F3}, '${F3}'))

1 Like