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
Nick_Steele
Frequent Visitor

Get median of all unique members of a group

Good Afternoon

 

I was hoping that someone could help me with my DAX woes.

 

According to the docs, GROUPBY with CURRENTGROUP doesn't support the MEDIANX or PERCENTILEX aggregations. I see that SUMMARIZE can be used as an alternative but SUMMARISE doesn't seem to be able to handle aggregations on virtual tables (which means I can't filter for unique values).

 

I have data that is essentially of the form found in the table below:

region  broker  metric  misc 1  misc 2   
aaa60zQqYs\lorvA[
aaa60ECOSCjNQLJLH
aab45J[Xi[aMXGfyy
aab45`LopySIWbv_d
aab45qOYCjEOwCd_V
bbc120ZYnNb_vjJKXn
bbd75M^rthXCU`XtX
bbd75n]H]qKqZG`dU
bbe30QlHAKziAHKMF

 

The value of metric is unique for each broker. I would like to get the average of the median broker per region (so as to give equal weight to each region in calculating the "median")

 

I've tried to calculate this by retrieving the unique region/broker/metric combinations as below:

regionbrokermetric
aaa60
aab45
bbc120
bbd75
bbe30

 

Then aggregating to get the median per region:

regionmedian(metric)
a52.5
b75

 

And finally taking the average to get the final "median"

Average(median(metric))
63.75

 

My measure currently looks like this:

 

median_region =
VAR __tbl =
    SUMMARIZE (
        GROUPBY ( table, table[region], table[broker], table[metric] ),
        [region],
        "median"MEDIAN ( [metric] )
    )
RETURN
    AVERAGEX ( __tbl, [median] )

OR alternatively

median_region =
VAR __tbl = SUMMARIZE (
    DISTINCT (
        SELECTCOLUMNS ( table, "r", [region], "b", [broker], "m", [metric] )
    ),
    [b],
    "median"MEDIAN ( [m] )
)
RETURN
    AVERAGEX ( __tbl, [median] )

Either way SUMMARISE cannot identify the context of the column [metric] so it results in an error.

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

2 REPLIES 2
wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1630990741383.png

 

Thanks so much, it works like a charm!

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.