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: 
thomas_2583
Contributor III
Contributor III

Calculate Field - Age

Hi, 

I am trying to created a new calculated field within Data Manager to group ages. I have written out this logic, but apparently, I am missing a parenthesis.  Can anyone please advise what has gone wrong? 

IF(Age <=45, '<45 Years',
IF(Age >= 46 and Age < 50, '46-50',
IF(Age >= 51 and Age < 55, '51-55',
IF(Age >= 56 and Age < 60, '56-60',
IF(Age >= 61 and Age < 65, '61-65',
IF(Age >= 66 and Age < 70, '66-70',
IF(Age >= 71 and Age < 75, '71-75',
IF(Age >= 76 and Age < 80, '76-80',
IF(Age >= 81 and Age < 85, '81-85',
'86+')))))))))

Labels (1)
2 Replies
Chanty4u
MVP
MVP

Hi

your expression looks correct. i didnt see any issue.  But you can try below  is working in my current project.

 

if(Age<=24,'Under 24',
if(Age>=25 and Age<=29,'25-29',
if(Age>=30 and Age<=34,'30-34',
if(Age>=35 and Age<=39,'35-39',
if(Age>=40 and Age<=44,'40-44',
if(Age>=45 and Age<=49,'45-49',
if(Age>=50 and Age<=54,'50-54',
if(Age>=55 and Age<=59,'55-59',
if(Age>=60 and Age<=64,'60-64',
if(Age>=65 and Age<=69,'65-69',
if(Age>=70 and Age<=74,'70-74',
if(Age>=75 and Age<=79,'75-79',
if(Age>=80 and Age<=84,'80-84',
if(Age>=85 and Age<=89,'85-89',
if(Age>=90 and Age<=94,'90-94',
if(Age>=95,'Over 95')))))))))))))))) as AgeRange;     

if this is working  you can replace with your original values.

Or
MVP
MVP

Data Manager does not accept 'AND'.  You don't need it in this case, either - just use

If(Age<-45,'<45 Years',

if(Age<50,'46-50',

etc.

Since by definition anything that isn't <= 45 is going to be >=46, etc.

Generally, though, if you can, I'd recommend using Data Load Editor instead to avoid limitations of this nature.