DAX in Excel - MEDIANX not working to provide a true median in Pivot

Nathag

New Member
Joined
Aug 1, 2013
Messages
17
I have the following DAX code in a data model pivot in order to provide a calculated field for median amount based data that needs to be summed before taking the median.
The median needs to appear based on specific categories of data.

=MEDIANX (
SUMMARIZE (
Range,
Range[INCOME_RANGE], Range[EMPLOYEE], "AMOUNT",
SUM ( Range[AMOUNT] )
),
[AMOUNT]
)

The problem is that in columns that have an even number of summed values, MEDIANX is only grabbing the first value rather than taking the average of the two middle values as would be typical in the normal way of calculating median.

For example, I have 40 rows after the summarize does its thing and sums the amount field. Row 20 is 9,945 and row 21 is 10,783.50. A normal Excel median formula would average those middle two out of the 40 rows to bring back 10,364.25, however, MEDIANX is merely grabbing the first of the two middle values to return 9,945 without doing the extra work. No, I do not have blank values.

What is up with that?? is there a way to fix this problem in DAX since I cannot use the regular MEDIAN formula due to the too many arguments error? There has to be a way to get a true median in a pivot table based on multiple sorting criteria.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
An update. If I use =MEDIANX(Range1, [AMT TEST]) with the rows already summed by employee in a separate sheet, then it provides the correct median of 10,364.25 in a data model pivot using the DAX for a calculated measure.

The problem it seems is with my SUMMARIZE expression within MEDIANX where for some reason when it is summing the data and then running median, a row is either getting dropped or the formula isn't counting it properly.
 
Upvote 0
Solution
BTW - I am using DAX in an Excel Pivot, not in PowerBI. Not sure why mods moved the thread except perhaps because no one uses DAX in Excel. :P
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top