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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MorePowerBI
Helper II
Helper II

Median of multiple columns in different tables

Hi everyone,

 

Is there a way to obtain the median value of two columns in different tables?

MorePowerBI_0-1649093427674.png

Table1 (left) and Table2 (right) - the Age column contains blank values (they're just filtered from this view)

Trying to find the median of the two Age columns which would be 49.

 

Is this doable without merging the table in Power Query editor?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MorePowerBI ,

 

This measure should work.

Measure = 
var _union = UNION(SELECTCOLUMNS(FILTER(Table1,Table1[_SDNCEAge]<>BLANK()),"age",Table1[_SDNCEAge]),SELECTCOLUMNS(FILTER(Table1,Table1[_SDNCEAge]<>BLANK()),"age",Table1[_SDNCEAge]))
return
MEDIANX(_union,[age])

 

Best Regards,

Jay

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @MorePowerBI ,

 

This measure should work.

Measure = 
var _union = UNION(SELECTCOLUMNS(FILTER(Table1,Table1[_SDNCEAge]<>BLANK()),"age",Table1[_SDNCEAge]),SELECTCOLUMNS(FILTER(Table1,Table1[_SDNCEAge]<>BLANK()),"age",Table1[_SDNCEAge]))
return
MEDIANX(_union,[age])

 

Best Regards,

Jay

lbendlin
Super User
Super User

Yes, sorry, the second argument is the field name from the first table.

Tried this but I get an error saying it can't find the column

RETURN

MEDIAN([_SDNCEAge])

 

I also CombinedTable[_SDNCEAge] but got the same error.

Might need to add a SELECTCOLUMNS  to rename them.

 

Please provide sanitized sample data that fully covers your issue. Not as a screenshot, please paste as text.


lbendlin
Super User
Super User

Use the UNION() operator to append the tables and then calculate the median from that union.

The two tables don't have the same number of columns.

 

EDIT:
I created a calculated table below:

 

CombinedTable=
FILTER (
UNION( VALUES(Table1[_SDNCEAge]), VALUES(Table2[_NCEAgeSP]) ),
NOT ISBLANK ( [_SDNCEAge] )
)
 
I can obtain the median this way but is there a way to do this without creating a calculated table? (i.e. store the CombintedTable as a variable in a measure and return the median)

yes, you can assign the result to a table variable

 

Measure = 
var CombinedTable=
FILTER (
UNION( VALUES(Table1[_SDNCEAge]), VALUES(Table2[_NCEAgeSP]) ),
NOT ISBLANK ( [_SDNCEAge] )
)
return medianx(CombinedTable)

or if you like it compact

 

Measure = medianx(
FILTER (
UNION( VALUES(Table1[_SDNCEAge]), VALUES(Table2[_NCEAgeSP]) ),
NOT ISBLANK ( [_SDNCEAge] )
)
)

 

 

I tried those but neither work. I get an error that says MEDIANX() requires a minimum of 2 arguments. I also tried MEDIAN() but then it tells me that this function only takes columns as arguments (since the VAR is a table)

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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