Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
robin_heijt
Creator
Creator

Generation based on Date of birth

Hi,

I am trying to assign generations to people based on their date of birth. However everyone keeps showing up as other.

Where am I making a mistake?

load*,

If(date("Date of birth">=01/01/1946) and (Date("Date of birth"<=01/01/1964)), 'Baby Boomer',

If(Date("Date of birth">=01/01/1965) and (date("Date of birth"<=01/01/1976)), 'Generation X',

If(date("Date of birth">=01/01/1977) and (date("Date of birth"<=01/01/1995)), 'Generation Y',

If(date("Date of birth">=01/01/1996) and (date("Date of birth"<=27/01/2018)), 'Generation Z', 'other' )))) as Generation;

Thanks

1 Solution

Accepted Solutions
OmarBenSalem

try:

load*,  

If(date("Date of birth")>='01/01/1946' and Date("Date of birth")<='01/01/1964', 'Baby Boomer',  

If(Date("Date of birth")>='01/01/1965' and date("Date of birth")<='01/01/1976', 'Generation X'

If(date("Date of birth")>='01/01/1977' and date("Date of birth")<='01/01/1995', 'Generation Y'

If(date("Date of birth")>='01/01/1996' and date("Date of birth")<='27/01/2018', 'Generation Z', 'other' )))) as Generation;

View solution in original post

7 Replies
undergrinder
Specialist II
Specialist II

Hi Robin,

Try this:

If(date("Date of birth")>=date(01/01/1946) and Date("Date of birth")<=date(01/01/1964), 'Baby Boomer',  

If(Date("Date of birth")>=date(01/01/1965) and date("Date of birth")<=date(01/01/1976), 'Generation X'

If(date("Date of birth")>=date(01/01/1977) and date("Date of birth")<=date(01/01/1995), 'Generation Y'

If(date("Date of birth")>=date(01/01/1996) and date("Date of birth")<date(=27/01/2018), 'Generation Z', 'other' ))))


(in the number of ')' can be error, please correct it if needed)

G.

dplr-rn
Partner - Master III
Partner - Master III

format looks wrong

i would suggest

date#("Date of birth") > date#('01/01/1946')

manoranjan_d
Specialist
Specialist

field name is case sensitive [] give inside the square bracket[Date of birth]

OmarBenSalem

try:

load*,  

If(date("Date of birth")>='01/01/1946' and Date("Date of birth")<='01/01/1964', 'Baby Boomer',  

If(Date("Date of birth")>='01/01/1965' and date("Date of birth")<='01/01/1976', 'Generation X'

If(date("Date of birth")>='01/01/1977' and date("Date of birth")<='01/01/1995', 'Generation Y'

If(date("Date of birth")>='01/01/1996' and date("Date of birth")<='27/01/2018', 'Generation Z', 'other' )))) as Generation;

undergrinder
Specialist II
Specialist II

Hi Maniranjan,

you are right, field names are case sensitives, but [field name] and "field name" are equivalent.

G.

manoranjan_d
Specialist
Specialist

load*, 

If(date("Date of birth",'MM/DD/YYYY')>='01/01/1946' and Date("Date of birth",'MM/DD/YYYY')<='01/01/1964', 'Baby Boomer', 

If(Date("Date of birth",'MM/DD/YYYY')>='01/01/1965' and date("Date of birth",'MM/DD/YYYY')<='01/01/1976', 'Generation X',

If(date("Date of birth",'MM/DD/YYYY')>='01/01/1977' and date("Date of birth",'MM/DD/YYYY')<='01/01/1995', 'Generation Y',

If(date("Date of birth",'MM/DD/YYYY')>='01/01/1996' and date("Date of birth",'MM/DD/YYYY')<='27/01/2018', 'Generation Z', 'other' )))) as Generation;

robin_heijt
Creator
Creator
Author

Thank you very much all.