Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Age Bucket Expression Question

Hi,

I am wondering what is wrong with my expression.  The IF statement works with just the first part, but if I add in the second parameters, I get the error "Error in expression:  If takes 2-3 parameters".  Can anyone help me to correct the syntax so that I have the specified 3 buckets?

=
IF


(

  (Round(  ((TODAY())-DOB)/365)  )            >=6
          
           and
 
  (Round(  ((Today())-DOB)/365)  )            <=17
 
)
 
  ,'6-17',


IF
(

  (Round(  ((TODAY())-DOB)/365)  )            >17
          
           and
          
  (Round(  ((Today())-DOB)/365)  )            <=65

)
 
  ,'18-65','OTHER'

1 Solution

Accepted Solutions
andrey_krylov
Specialist
Specialist

Hi Isabel. Maybe this

= IF(

  (Round(  ((TODAY())-DOB)/365)  )            >=6
           and
  (Round(  ((Today())-DOB)/365)  )            <=17 

  ,'6-17',

IF(

  (Round(  ((TODAY())-DOB)/365)  )            >17
           and
  (Round(  ((Today())-DOB)/365)  )            <=65

  ,'18-65', 'OTHER'))

View solution in original post

3 Replies
andrey_krylov
Specialist
Specialist

Hi Isabel. Maybe this

= IF(

  (Round(  ((TODAY())-DOB)/365)  )            >=6
           and
  (Round(  ((Today())-DOB)/365)  )            <=17 

  ,'6-17',

IF(

  (Round(  ((TODAY())-DOB)/365)  )            >17
           and
  (Round(  ((Today())-DOB)/365)  )            <=65

  ,'18-65', 'OTHER'))

Anonymous
Not applicable
Author

Yes, that's it, Perfect, Thanks!

Anonymous
Not applicable
Author

There were a few misplaced parentheses. The below should work.


=IF(Round(((TODAY())-DOB)/365)
>=6
and Round(((Today())-DOB)/365) <=17 ,'6-17',
IF(Round(((TODAY())-DOB)/365) >17 and Round((Today()-DOB)/365) <=65 ,'18-65','OTHER'))

Also, qlikview has a function for everything:


=IF(Age(TODAY(),DOB) >=6 and Age(TODAY(),DOB) <=17 ,'6-17',IF(Age(TODAY(),DOB) >17 and Age(TODAY(),DOB) <=65 ,'18-65','OTHER'))


To take it one step further you can do an interval match in the load to calculate the buckets.  If you'd like an example of that just reply and let me know.