Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
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'))

Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
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?

Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
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?

Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
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

Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
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