This is a late answer but you should have a look at this post:
https://datakuity.com/2022/10/19/optimized-median-measure-in-dax/