Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
detmawin
Contributor III
Contributor III

If Condition

I have a question, how can I create a flag or create an if statement based on the result from the first if statements.

Like if(statement 1=true,

then *and only then check* if (statement 2=true, 1) as Flag

Thank You

10 Replies
Anil_Babu_Samineni

I didn't understand, I assume this?

If(Statement1 = 'True' and Statement2 = 'True', 1, 0) as Flag

In future if you want to show only True Sales then you can use Flag like below

Sum({<Flag = {'1'}>}Sales)

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
sunny_talwar

May be this:

If(Statement1 = 'True',

     If(Statement2 = 'True', 1)) as Flag

or use Anil's approach....

detmawin
Contributor III
Contributor III
Author

Thanks for the replies, but here is my scenario.

I would like to create a flag from a list of possible fields from a previous flag.

i.e.  I created a flag for all students that passed their final test, now out of that flag of students, I want to get a count of all students that answered a particular question with a certain response.

I tried the above option nested if statement but my answer is null.  So it is like selecting all possible from a previous if statement.  I hope this makes sense.  Unfortunately, I do not have a .qvw to share on this. And I would like to create this final flag in the script if possible.

Thank you for your help.

sunny_talwar

Can you share the script at least?

detmawin
Contributor III
Contributor III
Author

Thanks, for example, so basically out of all of the student that scored>75, check to see if they got a particular response on number 23, then flag them.

Load

     *,

     if(Pass_Flg=1 and Question=23 and Response='Answer',1) as ExceptionStudent_Flg

Load

     Student,

     Grade,

     if(Grade>75,1) as Pass_Flg

     Question,

     Response

from table;

Thank you

sunny_talwar

This looks right to me, is this not giving you the result you are looking for?

detmawin
Contributor III
Contributor III
Author

no, I don t get any values

sunny_talwar

Seems to be working for me

Table:

LOAD *,

  If(Pass_Flg = 1 and Question = 23 and Response = 'Answer', 1) as ExceptionStudent_Flg;

LOAD *,

  If(Grade > 75, 1) as Pass_Flg;

LOAD * INLINE [

    Student, Grade, Question, Response

    A, 80, 23, Answer

    A, 72, 24, No

    A, 95, 25, Answer

    B, 65, 23, Answer

    B, 82, 24, Answer

    B, 92, 25, No

    C, 82, 23, No

    C, 65, 24, No

    C, 40, 25, No

    D, 98, 23, Answer

    D, 95, 24, Answer

    D, 93, 25, Answer

];

Capture.PNG

What's the difference between my example and your actual scenario?

detmawin
Contributor III
Contributor III
Author

Thanks I will check my data.