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: 
jzwi
Contributor
Contributor

Average Age per Unique ID

 

I am brand new to Qlik and having a hard time writing an expression for a KPI.  None of the other similar questions on the forum have resolved my problem.

I would like to return average of AGE, grouped by DISTINCT PATIENTID — that is, RecordNum 4 should not be included in the Avg calculation.

RecordNum | PatientID | Age | DateOfVisit |
1                       | 1234           |  15  |  1/24/2021  |
2                       | 2345           |  66  |  1/25/2021  |
3                       | 3456           |  45  |  2/10/2021  |
4                       | 1234           |  15  |  2/19/2021  |


The expected result is 42:  (15 + 66 + 45)/3

I'll forgo cluttering this question with my various attempts, but any help is appreciated.

Labels (3)
2 Replies
chaorenzhu
Creator II
Creator II

Sum(Aggr(Age, PatientID))/count(distinct PatientID)

chaorenzhu
Creator II
Creator II

but what if the age changes? say for patient 1234, on 2/19/2021 this person becomes 16 years old? in case you want the avg, use Sum(Aggr(avg(Age), PatientID))/count(distinct PatientID)