How to use the IF function to display a numeric value for analysis based on a previous answer

Hi All

I am trying to analyse some information that is not numeric by making it numeric.

So, There are 4 questions in which people are allow to select a range as there answer using "select_one": 0-50,000, 50,001 - 150,000 etc. When this downloads as raw data is not numeric as my "choices" show 0_50, 51_150, 151_300 etc.

What i need to do is have a score assigned to each selection. for Q1: 0-50,000 = 6, 51,000_150,000 = 5 and so on down to 1

but of the 4 questions 2 go in that sequence and 2 go in the opposite sequence, i.e. 0-50,000 = 1, 51,000 - 150,000 = 2 etc.

I cannot make the "name column" 1,2,3,4 etc as A: i have them in another part of the questionnaire, B i need them twice for the above example, 1-6 and 6-1.

So, my solution is to use the calculate function for each of the 4 questions and in the calculation use IF. IF 0-50,000 "6", IF 51,000 - 150,000 "5" etc

Is this possible? This way when i download the data it will be numeric

What i will end up with are 3 columns of raw data for each question:

Estimated Income? yes, no, don't know, refuse
Range: 0_50, 51_150, 151_300 etc
Score: 1, 2, 3, etc

This way i can analyse the selected range via the calculated score.

Thanks in advance for you help

Nick

Try something like this (basically a nested XPath if):

<bind nodeset="/data/score" calculate="if(/data/range='0_50', 1, if(/data/range='51_150', 2, if(...)))" type="int">

you're going to have to explain that a little bit to me :slight_smile:

a: whats a nested XPath?
b: Where would i put something like this?

(sorry, i'm not very techy)

Much appreciated

Ah. What I wrote is how it'll appear in the eventual XForm XML document; but me thinks you are using a XLSForm-based form builder, huh? In which case, it'll be more like a calculate 'control' with something like

if(${range}='0_50',1,if(${range}='51_150',2,if(...)))

does that help?

3 Likes

Ah i see, yea that is what i was looking for, how to use the IF bit in the calculate column.

Let me give that a go and i'll if it works.

Thanks

1 Like