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

Expression with one result from nested if statements

Hi All

I am trying to construct an expression that uses nested if statements to arrive at a value depending on input of dynamic variables. If ALL the if statements are true then I want to assign a value - ie IF condition 1 is true AND condition 2 is true AND condition 3 is true THEN assign the value.

My sceanrio relates to a lot number of an inventory item that has a number of tests done against it. The user enters the acceptable range of results for each test into input fields. The expression then uses conditions like:

if(test='Moisture' and results >= MoistureRangeFrom and results <= MoistureRangeTo)

if(test='Purity' and results >= PurityRangeFrom and results <= PurityRangeTo)

If ALL of these conditions are true THEN the result should be 'Pass' else 'Fail'

How do I construct the expression to arrive at a single result for all Test results?

Thanks, Kevin

3 Replies
Not applicable
Author

Try this please

if(test='Moisture' and results >= MoistureRangeFrom and results <= MoistureRangeTo, if(test='Purity' and results >= PurityRangeFrom and results <= PurityRangeTo, 'TRUE', 'FALSE'))

Not applicable
Author

Thanks for the suggestion Richard. This does not quite work as the aim is for both test conditions to be within range (there are in fact 7 tests that have to be passed for a successful acceptance).

When evaluated, this suggested expression will still return a TRUE value if the Purity test passes even if the Moisture test does not pass. In this example I want FALSE returned because both tests do not pass.

I'm open to suggestions other than nested if statements if anyone can think of some alternative.

Thanks, Kevin

Anonymous
Not applicable
Author

If you want to pass every expression as true there's only two way's I guesse:

if( (test = 'Moisture' and results => MoistureRangeFrom and results <= MoistureRangeTo)), if(test='Purity' and results >= PurityRangeFrom and results <= PurityRangeTo), 'Pass','Fail'),Fail)


if( (test = 'Moisture' and results => MoistureRangeFrom and results <= MoistureRangeTo)) and (test='Purity' and results >= PurityRangeFrom and results <= PurityRangeTo) , 'Pass','Fail')