Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
livio218526
Creator
Creator

Nested IF with AND operator in Qlik Sense

Hi everyone,

i have a problem when i try to create a new calculated field by using a Nested IF.

For example I have a Field Age and I want create a new Field (Color) with 'A' if Age > 10 and < 20, 'B' if Age >=20 and < 40 and so on...

I try to create this function but Qlik show me this error: missing right parenthesis:


if(Age > 10 and Age < 20,A,

7 if(Age >= 20 and Age < 40,B,))

Thanks,

Livio

36 Replies
livio218526
Creator
Creator
Author

If([City Code] > 100 and [City Code]<20, 'A',

     If([City Code] >= 20 and [City Code] < 40, 'B'))

Anil_Babu_Samineni

True, Qlik consider as 2 fields which called appending. So, you could try [City Code] instead City Code

If([City Code]> 100 and [City Code] <20, 'A', If([City Code] >= 20 and [City Code] < 40, 'B'))

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
Or
MVP
MVP

If your field is called City Code, you have to use [City Code].

You should also name your column:

if(Stuff) as CityCodeColor

livio218526
Creator
Creator
Author

Hi,

I solve the problem by using the Data Loader but I don't undertand why it's no function using "Add Calculated Field" in Data Model

Anil_Babu_Samineni

If..Else.. Available in Script and UI too. Where it not working for you? Can you show image at least?

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
livio218526
Creator
Creator
Author

Hi,

If i use the DATA MANAGER the result is:

qlik.jpg

By using Data Loader the script is ok and i'm able to create the calculated filed that you can see in the picture up.

Anil_Babu_Samineni

Seems, Data manager also working. Where you facing the wrong values?

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
livio218526
Creator
Creator
Author

In the Data Manager like you can see in the picture

Anil_Babu_Samineni

You may miss understanding the IF condition

If([City Code]> 10 and [City Code] <20, 'A', If([City Code] >= 20 and [City Code] < 40, 'B', 'C'))

Explanation - If [City Code] arbitrary between 10 and 20 then it returns only A and [City Code] arbitrary between 20 and 40 then it returns only B. That means, If [City Code] < 10 and [City Code] >40 it returns C only. The same way your functionality works

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
livio218526
Creator
Creator
Author

I'm sorry but if i use this script:

If([City Code]> 10 and [City Code] <20, 'A', If([City Code] >= 20 and [City Code] < 40, 'B', 'C'))

the result is ever wrong It's ok only if i use the data loader editor