Qlik Community

Qlik DataMarket Discussions

Discussion Board for collaboration regarding Qlik DataMarket.

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Not applicable

Create a new column and populate it with recoded variables

Hi All,
Here is my question:

I have uploaded an excel file where there is a column with a list of email addresses and a column called ''answers''.
In this column there are numerical values from 1 to 100.
Now, I know that those who answered giving a value equal or greater to 54 gave the correct answer, while the others answered wrong

What I want to do is to create a new column, called ''answers recoded'' where I simply put CORRECT when the person answered =>54 and WRONG for all the other values.

Please kindly let me know if you have any ideas. Since I am a very beginner, please also tell me if I have to write the ''If-else'' conditions in the script or somewhere else.

Best,

Paolo

4 Replies
Highlighted
MVP & Luminary
MVP & Luminary

Re: Create a new column and populate it with recoded variables

Try this:

Load "email addresses", "answers", if(''answers'' > 54, 'CORRECT', 'WRONG') as "answers recoded"

from YourExcel;

- Marcus

Highlighted
Not applicable

Re: Create a new column and populate it with recoded variables

Hi Marcus,

Thanks for your swift reply,


I managed to load the data without any bug, please see if the code below makes sense (the if else condition is slightly different. If the "your_answer" column contains values such as #javascript, #java or 28, it is correct, otherwise it's wrong)

LOAD

    ip_address,

    your_answer,

    if(your_answer = 28 or '#javascript' or '#java', 'CORRECT', 'WRONG') as "answers recoded", //Recode 'your_answer' to Correct / Wrong in a new empty column

    utm_medium,

    utm_content

FROM [lib://Documents/clients\All Javascript Leads (p).csv]

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

What do you think about it?

Many thanks,

Paolo

Highlighted
MVP & Luminary
MVP & Luminary

Re: Create a new column and populate it with recoded variables

Yes, it looked good unless you need to repeat the fieldname to each checking like:

...

if(your_answer = 28 or your_answer = '#javascript' or your_answer = '#java', 'CORRECT', 'WRONG') as "answers recoded",

...

But by several values to check I would take a match-function like:

...

if(match(your_answer, 28, '#javascript', '#java'), 'CORRECT', 'WRONG') as "answers recoded",

...

- Marcus

Highlighted
Not applicable

Re: Create a new column and populate it with recoded variables

Ok, thanks a lot!

Paolo