Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
JustinM
Contributor III
Contributor III

How to calculate average age per id instead of per line

Hi

I'm trying to work out average age of a number of ids with multiple rows of same id. Currently I'm only getting it to calulate the average based on the number of rows instead of the ids.

I have the following Data:

ID Start Date End Date Age
1 01-Jan-22 20-Jan-22 19
1 01-Jan-22 20-Jan-22 19
1 01-Jan-22 20-Jan-22 19
2 10-Jan-22 15-Jan-22 5
2 10-Jan-22 15-Jan-22 5
3 11-Jan-22 25-Jan-22 14

 

I am looking for an answer of 13 (19+5+14)/3  but I'm getting 14 (81/6)

My current formula is (sum([End Date])-sum([Start Date]))/count([ID])

i'm thinking I need to build some kind of distinct count or similar in

Any help is appreciated

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I believe 

=Sum(Aggr([End Date] - [Start Date], ID)) / Count(Distinct ID) 

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

3 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I believe 

=Sum(Aggr([End Date] - [Start Date], ID)) / Count(Distinct ID) 

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

krishna_2644
Specialist III
Specialist III

Hi - Rob's Solution works perfectly fine.

if you want to calculate the avg price in script then May be this?

Capture.JPG

JustinM
Contributor III
Contributor III
Author

Thanks Rob - That works