How to generate dynamic labels based on a calculation

Colleagues, I’m struggling to find a workaround for the following flow of questions. I made a simple example for what I’m intending to do.

These are my example questions:

And these are my example choices:
Screen Shot 2021-02-05 at 11.45.43

Basically, the question starts asking in which city the respondent is located. Based on this response, it then calculates the country the city corresponds to. Then it asks a question using the label of the country, no the city.

But I’m not sure how to make this work WITHOUT asking first in which country are you and then in which city are you (which I don’t want to do).

I guess it could be done with from a preloaded data that links each city with each country and reads from there, but it sounds burdensome.

Thanks for the suggestions. I attach the file here.Autolabel.xlsx (10.0 KB)

Welcome back to the community @guiu! Maybe you could try using the cascading select question for this:

Thank you @Kal_Lam. I’m actively trying to avoid using the cascading format. I prefer not to ask first country, then district, then city. I prefer the survey to directly assume that, if the respondent says he/she is in Madrid, means the country is Spain.

I do know this will be possible with Or with the code below. But it is always preferable not to use strings when later exporting the dataset for data analysis.

1 Like

If you’re doing a single language form then you could always add an extra column in your choice list - e.g. call it Country, and put the country code against each City in the choice list.

Can then use instance() to pull the data by specifying XML path - just like you would use pulldata() from an external file but in this case the data is coming from within the same XLSForm file (an additional column in the choice tab).

@NoelCartONG gave me this handy example the other day, which might help: example pulling data from additional choice list columns.xlsx (28.7 KB)

1 Like

That’s super interesting, @nat. Definitely I’ll make use of it.

1 Like