Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
RonD
Frequent Visitor

Finding the Mean, Median, and Range of a calculated DAX measure

Please help. I am almost certain that mine is a simple problem with a simple solution but I have spent quite a number of days on it without a breakthrough. Below is a sample of a large spreadsheet of patient data that I'm using to measure and visualize hospital performance on some metrics in Power BI Desktop. One of the metrics is the percentage of patients who have a pressure ulcer (an injury to the skin caused by prolonged pressure on the skin when patients are in bed for long periods).  

PatientHospitalDatePressure Ulcer Present
101100H0128/07/2022No
101101H0128/07/2022Yes
101102H0128/07/2022Yes
101103H0128/07/2022Yes
101104H0228/07/2022No
101105H0228/07/2022No
101106H0228/07/2022Yes
101107H0228/07/2022No
101108H0328/07/2022Yes
101109H0328/07/2022No
101110H0328/07/2022No
101111H0328/07/2022Yes
101112H0428/07/2022No
101113H0428/07/2022No
101114H0428/07/2022No
101115H0428/07/2022Yes
101116H0528/07/2022Yes
101117H0528/07/2022Yes
101118H0528/07/2022No
101119H0528/07/2022No
101120H0528/07/2022No

 

So for this example, I am using a DAX measure to calculate the Pressure Ulcer metric for each Hospital as a percentage of patients with a pressure ulcer as follows:

Pressure Ulcer Metric =
VAR Num = CALCULATE(COUNTROWS('Patients'), NOT(ISBLANK('Patients'[Pressure Ulcer Present])) && 'Patients'[Pressure Ulcer Present] = "Yes")
VAR Den = CALCULATE(COUNTROWS('Patients'), NOT(ISBLANK('Patients'[Pressure Ulcer Present])))
RETURN
IF(ISBLANK(Num), 0, DIVIDE(Num, Den))
 
By the way, patients that have a blank entry for the pressure ulcer are excluded hence the 'ISBLANK' check. So the results the above DAX code would be:
HospitalPressure Ulcer Metric
H0175%
H0225%
H0350%
H0425%
H0540%
 
This is all working fine but after calculating the measure for each Hospital, I would like to calculate the Average, Median, Minimum, and Maximum across all the individual Hospital measures (in order to give hospital managers some idea of where they stand against other hospitals): this is what I am struggling to do. So for this example, I want to know how to calculate and get:
Average Pressure Ulcer Metric43%
Median Pressure Ulcer Metric40%
Minimum Pressure Ulcer Metric25%
Maximum Pressure Ulcer Metric75%
 

I have struggled to get this to work and I haven't seen anything similar to this on the forum. So I would appreciate some help. Thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @RonD ,

 

I think you can try measures as below.

Average Pressure Ulcer Metric = 
AVERAGEX(VALUES(Patients[Hospital]),[Pressure Ulcer Metric])
Median Pressure Ulcer Metric =
MEDIANX ( VALUES ( Patients[Hospital] ), [Pressure Ulcer Metric] )
Maximum Pressure Ulcer Metric =
MAXX ( VALUES ( Patients[Hospital] ), [Pressure Ulcer Metric] )
Minimum Pressure Ulcer Metric = 
MINX(VALUES(Patients[Hospital]),[Pressure Ulcer Metric])

Result is as below.

RicoZhou_0-1659344190291.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@RonD , The above should give correct Avg -Pressure Ulcer Metric

try

AverageX(Values('Patients'[Patients]) , [Pressure Ulcer Metric])

 

MAxx(Values('Patients'[Patients]) , [Pressure Ulcer Metric])

 

Minx(Values('Patients'[Patients]) , [Pressure Ulcer Metric])

 

MedianX(Values('Patients'[Patients]) , [Pressure Ulcer Metric])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you @amitchandak. I realise that I may not have properly explained what I am trying to achieve and so I have edited my post to make it clearer. Your suggestion just reproduces the individual Hospital Pressure Ulcer Metrics which I am able to calculate with the DAX code in my post and a slicer on the Hospital column. But after calculating the measure for each Hospital, I would like to calculate the Average, Median, Minimum, and Maximum across all the individual Hospital measures (in order to give hospital managers some idea of where they stand against other hospitals): this is what I am struggling to do.

Anonymous
Not applicable

Hi @RonD ,

 

I think you can try measures as below.

Average Pressure Ulcer Metric = 
AVERAGEX(VALUES(Patients[Hospital]),[Pressure Ulcer Metric])
Median Pressure Ulcer Metric =
MEDIANX ( VALUES ( Patients[Hospital] ), [Pressure Ulcer Metric] )
Maximum Pressure Ulcer Metric =
MAXX ( VALUES ( Patients[Hospital] ), [Pressure Ulcer Metric] )
Minimum Pressure Ulcer Metric = 
MINX(VALUES(Patients[Hospital]),[Pressure Ulcer Metric])

Result is as below.

RicoZhou_0-1659344190291.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

That works! Thanks @Anonymous 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.