Forum Discussion

skutovicsakos's avatar
6 years ago
Solved

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!

  • I think this should work

     

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

1 Reply

  • MattAllington's avatar
    MattAllington
    Icon for Community Champion rankCommunity Champion

    I think this should work

     

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