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

Average Age with months for all ID's

Hi ,

i need average of the ages in a text box. the age should be year.months format. for example 1.3 something like that.

Note:i need this is text box not in the chart.

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Today is 17/07/2015... If you want to Calculate from 17/06/2015, use as below

=Avg(Aggr(age(AddMonths(Today(),-1),Birthdate) & ',' & (if(day(AddMonths(Today(),-1)) >= day(Birthdate),

  mod((Year(AddMonths(Today(),-1))*12+Month(AddMonths(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12),

  if(mod((Year(AddMonths(Today(),-1))*12+Month(AddMonths(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12)=0,11,

  mod((Year(AddMonths(Today(),-1))*12+Month(AddMonths(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12)-1))),MEM_ID))

If you want to calculated from End Of Previous Month i.e. 30/06/2015

=Avg(Aggr(age(MonthEnd(Today(),-1),Birthdate) & ',' & (if(day(MonthEnd(Today(),-1)) >= day(Birthdate),

  mod((Year(MonthEnd(Today(),-1))*12+Month(MonthEnd(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12),

  if(mod((Year(MonthEnd(Today(),-1))*12+Month(MonthEnd(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12)=0,11,

  mod((Year(MonthEnd(Today(),-1))*12+Month(MonthEnd(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12)-1))),MEM_ID))

View solution in original post

10 Replies
Anonymous
Not applicable
Author

round(avg( Age(Today(), Birthdate ) ))

See attached.

MK_QSL
MVP
MVP

=AVG(Aggr(age(Today(),Birthdate) + (if(day(Today()) >= day(Birthdate),

  mod((Year(Today())*12+Month(Today()))-(Year(Birthdate)*12+Month(Birthdate)),12),

  if(mod((Year(Today())*12+Month(Today()))-(Year(Birthdate)*12+Month(Birthdate)),12)=0,11,mod((Year(Today())*12+Month(Today()))-(Year(Birthdate)*12+Month(Birthdate)),12)-1)))/12,MEM_ID))

Anonymous
Not applicable
Author

Thank you Bill, can we also include months as well along with number of years

sunny_talwar

Not sure if you want this, but check it out.

Best,

Sunny

Anonymous
Not applicable
Author

since we are in July, i need the month to be taken as Currentmonth-1.. Can you please help me with that

MK_QSL
MVP
MVP

Replace below instead of Today()

AddMonths(Today()-1)

Anonymous
Not applicable
Author

i have to change in all the places

Anonymous
Not applicable
Author

i soon as i do that i am getting an error ...

MK_QSL
MVP
MVP

Today is 17/07/2015... If you want to Calculate from 17/06/2015, use as below

=Avg(Aggr(age(AddMonths(Today(),-1),Birthdate) & ',' & (if(day(AddMonths(Today(),-1)) >= day(Birthdate),

  mod((Year(AddMonths(Today(),-1))*12+Month(AddMonths(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12),

  if(mod((Year(AddMonths(Today(),-1))*12+Month(AddMonths(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12)=0,11,

  mod((Year(AddMonths(Today(),-1))*12+Month(AddMonths(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12)-1))),MEM_ID))

If you want to calculated from End Of Previous Month i.e. 30/06/2015

=Avg(Aggr(age(MonthEnd(Today(),-1),Birthdate) & ',' & (if(day(MonthEnd(Today(),-1)) >= day(Birthdate),

  mod((Year(MonthEnd(Today(),-1))*12+Month(MonthEnd(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12),

  if(mod((Year(MonthEnd(Today(),-1))*12+Month(MonthEnd(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12)=0,11,

  mod((Year(MonthEnd(Today(),-1))*12+Month(MonthEnd(Today(),-1)))-(Year(Birthdate)*12+Month(Birthdate)),12)-1))),MEM_ID))