cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper II
Helper II

Median of multiple columns (some columns have blanks)

I need a method for calculaing the median of multiple (3) columns. I tried using MEIDIANX but realized it was taking blanks and zeros into account and providing incorrect results. I then tried to add a FILTER to the argument but got an error saying "Expressions that yield variant data-type cannot be used to define calculated columns." so I'm at a loss now. I'm unable to supply the data as it's incredibly large and contains sensitive elements. This is what I had written:

 

New Column=

MEDIANX(

FILTER(

'tableA',{'tableA[column1],'tableA',{'tableA[column2],'tableA',{'tableA[column3]} <> BLANK() ),

{'tableA[column1],'tableA',{'tableA[column2],'tableA',{'tableA[column3]})

 

I also tried lots of other combinations of including or not including the table names, using a VALUE expression, none of which produced accurate results and most of which produced syntax errors. I'm sure this is incredibly simple but I'm at a loss. I'm still very new to DAX and getting more frustrated every day. I appreciate any and all help.

 

Thanks. 

5 REPLIES 5
Super User IV
Super User IV

@DJBAJG Probably should unpivot, but if you don't want to do that, https://community.powerbi.com/t5/Quick-Measures-Gallery/Multi-Column-Aggregations-MC-Aggregations/m-...

 

Also, make sure to read this to avoid pain and suffering!! https://community.powerbi.com/t5/Quick-Measures-Gallery/To-bleep-With-MEDIAN/m-p/1322755#M599


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I don't think this works. Here's a screenshot of my output and the measure. The dark blue bar in the graph should represent the median of all of the values in the chart, ignoring blanks. 17 non-blank values, order, take the middle. That would give us $2,500. I tried a few different ways but I'm actually unable to get $1,225. What am I missing? Does this not work when filtered? 

 

Table.PNG

 

You can see I'm using 5 columns. Did it do the measure incorrectly when creating the tmpTable?

 

Code.PNG

 

 

Just figured it out. Because it's using MEDIANX it's taking the blanks into account and treating them as zeros. This doesn't work for me. Any way around this in your example of do we need a different solution? 

Come on community. I've a newbie here and this is probably incredibly simple. 

Please! Still need help here. I'm spinning my wheels getting nowhere on my own. 😞 

Here's the answer. Like I assumed, incredibly simple for probaly 99% of the people on this forum but tough for me. Wish someone would have chimed in. Could have saved my a day....

 

Capture.PNG

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors