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

How to create a age group

I have AGE filed in my table. I want convert it into Age group. 

Age

21

14

15

19

25

32

I want covert like if AGE= (1-20) Young, (21-30)Middle. (31-40)Upper

Labels (1)
3 Replies
PrashantSangle

Hi,

 

try with simple if else statement in script

try like

if(age>0 and age<21,'Young',if(age>21 and age<31,'Middle',if(age>30 and age<41,'Upper'))) as  age_group

or

if(age>0 and age<21,'Young',if(age>21 and age<31,'Middle','Upper')) as  age_group

 

Regards

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
qlikviewwizard
Master II
Master II

Hi,

Please try this.

I included logic for Age > 40 as well. You can remove if it is not needed.

Data:
LOAD *,if(Age<=20 ,'Young',
if(Age>=21 and Age<=30 ,'Middle',
if(Age>=31 and Age<=40 ,'Upper','Other'
))) as [Age Group];
LOAD * INLINE [
Age
1
11
14
18
21
14
15
19
25
32
42
54
65
88
100];



Capture.PNG

Capture1.PNG

timpoismans
Specialist
Specialist

Can possibly also use IntervalMatch:

Age:
Load * Inline [
Age
21
14
15
19
25
32
];

AgeInterval:
Load * Inline [
Min, Max, AgeGroup
1, 20, Young
21, 30, Middle
31, 99, Upper
];

Inner Join IntervalMatch (Age)
Load
Min,
Max
Resident AgeInterval;

Left Join (Age)
Load
Age,
AgeGroup
Resident AgeInterval;
Drop Table AgeInterval;