4 Replies Latest reply: Aug 17, 2016 5:24 AM by Joerg Linder

# Calculate Median from grouped data

Dear all,

I would like to calculate the median value  for each prescription ID as well as for each patient ID regarding product sales (see attached data example).

I can calculate the average value for each patient by using "Sum([Sales per prescripton line])/Count(distinct(PAT_ID))".

I can calculate the median value of the prescription line but how do I get the median value for prescription ID and patient ID?

Jörg

• ###### Re: Calculate Median from grouped data

Perhaps simply median([Sales per prescripton line])

• ###### Re: Calculate Median from grouped data

Thank you for your answer. I have already done that and got the median for prescription line but how do I obtain the median for prescription  and patient?

Jörg

• ###### Re: Calculate Median from grouped data

I don't understand what you want. Perhaps one of these three is what you're looking for:

• median(aggr(sum([Sales per prescripton line]),[Patient ID]))
• median(aggr(sum([Sales per prescripton line]),[Unique Prescription ID]))
• median(aggr(sum([Sales per prescripton line]),[Patient ID],[Unique Prescription ID]))
• ###### Re: Calculate Median from grouped data

Hi Gysbert,

Sorry for not explaining it properly but you actually gave me the looked for answer.

Well done, thank you

Jörg