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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors