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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
skutovicsakos
Helper I
Helper I

median based on distinct values in another column

Hello,

 

I have data that looks like this:

 

EmployeeEmploymentAge 
1a35
1b35
2a40
3a 
4a51
4b51

 

I want to calculate the median age of the individual employees. Simply taking the median of age column is not good, since it counts Employee 1 and 4's ages twice.

 

I need a measure that counts distinct values in the employee column, then takes their median age. (Employees with blank age shouldn't be calculated)

 

Any idea about a formula that could do this?

 

Thanks!

1 ACCEPTED SOLUTION
MattAllington
Community Champion
Community Champion

I think this should work

 

calculate(Medianx(values(table[employee]),calculate(average(table[age]))),table[age]>0)



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

1 REPLY 1
MattAllington
Community Champion
Community Champion

I think this should work

 

calculate(Medianx(values(table[employee]),calculate(average(table[age]))),table[age]>0)



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.