Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Shridhara
Contributor
Contributor

Unable to create a new Calculated field.

In my dataset I have a "Age" field and I want o create a new calculated field based on the existing "Age" field named as "Age Category" in such a way that :

0 - 12 : Kid

13 - 17 : Teen

18 - 64 : Adult

Above 65 : Senior

I have used the following expression to create the field but It is not working, It shows Incomplete visualization in the 

preview section. How to resolve this?

If(Age >= 0 & Age < 13,'Kid',
IF(Age >= 13 & Age<18,'Teen',
IF(Age >=18 & Age< 65,'Adults',
if(Age >= 65,'Senior'))))

Labels (3)
1 Solution

Accepted Solutions
Or
MVP
MVP

Are you using the Data Load Manager? It unfortunately does not allow the use of AND statements, so you'll have to just follow the nested if() statements. Which may actually be preferable in the first place since it's shorter (but somewhat harder for a human to read, I guess):

If(Age < 13, 'Kid',

if(Age < 18, 'Teen',

If(Age < 65, 'Adult', 'Senior')))

View solution in original post

5 Replies
Or
MVP
MVP

Use "and" rather than "&".

Shridhara
Contributor
Contributor
Author


@Or wrote:

Use "and" rather than "&".


Even I tried with that, if I use "and" it will shows 'no preview enter valid expressions'.

qv_testing
Specialist II
Specialist II

Try this 

If(Age >= 0 and Age < 13,'Kid',
  IF(Age >= 13 and Age<18,'Teen',
    IF(Age >=18 and Age< 65,'Adults',
      if(Age >= 65,'Senior')))) as FieldName

if this is not working, please share the sample data.

Or
MVP
MVP

Are you using the Data Load Manager? It unfortunately does not allow the use of AND statements, so you'll have to just follow the nested if() statements. Which may actually be preferable in the first place since it's shorter (but somewhat harder for a human to read, I guess):

If(Age < 13, 'Kid',

if(Age < 18, 'Teen',

If(Age < 65, 'Adult', 'Senior')))

TauseefKhan
Creator III
Creator III

Result:

TauseefKhan_0-1716108142048.png

LOAD *,
If(Age >= 0 and Age <= 12, 'Kid',
If(Age >= 13 and Age <= 17, 'Teen',
If(Age >= 18 and Age <= 64, 'Adult',
If(Age >= 65, 'Senior')
)
)
) as [Age Category]
RESIDENT [YourTableName];

*** When applicable please mark the correct/appropriate replies as "solution". Please LIKE threads if the provided solution is helpful to. ***