Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

where clause inside if statement

I have a small piece of code which basically checks if the question is 2 or 3 and

If the question is 3, it saves the corresponding answer as Final answer.

What I need is if the question is 2, it shows test for now but  I would still like to save the Final answer as whatever was answer for question 3.

Is there a way I can achieve this? Any help will be appreciated

LOAD distinct

     DataPoint,

     if (Question=3,Answer,'test' ) as [Final Answer]

FROM

$(vQVDLocation)DataPointAnswerChoice.qvd

(qvd) where match(Question,2,3);

The pseudo code is something along below lines

if( question =3, answer, ( answer where question would have been 3) )

1 Solution

Accepted Solutions
anbu1984
Master III
Master III

Tbl:

LOAD distinct

     DataPoint,

     if (Question=3,Answer,'test' ) as Answer3,

     Question

FROM

$(vQVDLocation)DataPointAnswerChoice.qvd

(qvd) where match(Question,2,3);

Join(Tbl)

LOAD

     DataPoint,

     2 As Question,

     Answer As Answer2

FROM

$(vQVDLocation)DataPointAnswerChoice.qvd

(qvd) where Question=3;

Final:

Load *, if (Question=3,Answer3,Answer2 ) as [Final Answer] Resident Tbl;

Drop Table Tbl;

View solution in original post

12 Replies
robert_mika
Master III
Master III

Maybe firstsortedvalue is the answer

How is your data structured.

Could you post an examples?

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Do you want to save the answer from question 3 as the answer for question 2?

-Rob

Not applicable
Author

Yes

Not applicable
Author

Thanks, i'll look up firstsortedvalue. The data structure is complex and I do a lot of manipulations but basically it has a column to note the questions and answers as shown above.

anbu1984
Master III
Master III

What is the common field between rows where Question is 2 or 3?

Does both rows have same datapoint?

Not applicable
Author

Yes Data Point is the same.

anbu1984
Master III
Master III

If DataPoint is same and if you assign Answer of Question=3 to Question=2, both the rows will have same values as you have only two fields selected in Load statement. Then why do you need to assign Answer of Question=3 to Question=2?

Not applicable
Author

I actually have more statements like assigning the score and time stamp. I just copied the part where I assign value to Final Answer. I also have series of load statements written when question equals to 4, 5 etc,,

robert_mika
Master III
Master III

Post some of your data to better understand your requirement