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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Median of a filtered measure

I'm trying to calculate the median of a Market Share measure by store size. 

 

I've got Table 1 which has store names, store size (big or small), category (e.g. fruit, veg) and units sold.

 

I have a measure:

 

Market share sales = DIVIDE(SUM('Table1'[Units sold]),CALCULATE(SUM('Table1'[Units sold]),ALL('Table1'[Store Name],'Table1'[Store Size])))

 

Which calculates the market share for a particular store and/or category of food. When I filter for store size the market share remains the same (which it should).

 

I want to be able to calculate the median of the market share by store size.

 

I've got

 

Big Median Market Share =
CALCULATE(MEDIANX (
SUMMARIZE (
'Table1',
'Table1'[Store Name],
"MShare", DIVIDE(SUM('Table1'[Units sold]),CALCULATE(SUM('Table1'[Units sold]),ALL('Table1'[Store Name])))
),
[MShare]
),FILTER(Table1,Table1[Store Size]="Big"))

 

But this doesn't give me the right answer (too high). If I change the ALL to ALL('Table1'[Store Size] then I just get median market shares of 100%

 

Can anyone help? I suspect I'm doing dodgy things with the filters but I just can't work out how to fix it. 

 

Thanks in advance!

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

We can create a measure as below.

 

Measure = MEDIANX(VALUES(Sheet1[Store]),[Market Share Sales])

Capture.PNG

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

4 REPLIES 4
v-frfei-msft
Community Support
Community Support

Hi @Anonymous,

 

Did you try to use ALLEXCEPT or Values? Could you please share your pbix and excepted result to me? if you don't have confidential data? Please upload your file to One Drive and share the link here.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Hi @v-frfei-msft and thanks for replying.

 

I've uploaded a pbix file here: https://1drv.ms/u/s!AjkKjlnY4o11hCa1KWzBV-0fIfwM

 

Median Market share (for Store type = Franchise) should be 

 

2015 - 0.98%

2016 - 3.51%

2017 - 0.03%

 

I've tried ALLEXCEPT but not VALUE. 

 

I think it's calculating the median without filtering for store type, but if I add Store Type to the Median Market share then they all come out at 100%. 

 

Help very gratefully appreciated!

 

 

 

 

 

Hi @Anonymous,

 

We can create a measure as below.

 

Measure = MEDIANX(VALUES(Sheet1[Store]),[Market Share Sales])

Capture.PNG

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Thank you @v-frfei-msft that gives the correct answer!

 

I've modified it slightly to:

 

Measure = CALCULATE(MEDIANX(VALUES(Sheet1[Store]),[Market Share Sales]),Sheet1[Store Type]="Franchise")

So that it always shows the median for the Franchises (just adding it here so I remember for the future!).

 

Your help is greatly appreciated!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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