Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi everyone,
Is there a way to obtain the median value of two columns in different tables?
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?
Solved! Go to Solution.
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
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
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.
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:
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)
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 46 | |
| 43 | |
| 39 | |
| 19 | |
| 15 |
| User | Count |
|---|---|
| 68 | |
| 67 | |
| 31 | |
| 27 | |
| 24 |