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
DJBAJG
Helper III
Helper III

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. 

6 REPLIES 6
Uldevi
Regular Visitor

Hi, I have got same issue regarding MEDIANX did you get any solution for that , can you share with me how can I achieve it.....Thank you !

Greg_Deckler
Super User
Super User

@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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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
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.