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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
LCTurner
New Member

SUMMARIZE table with filter

Hi all,

 

I have some salary data with these variables:
UNIQ_ID = a unique identifier for each row of data (i.e. each employee)
ORGDATA_CPY_NAME = the name of the organisation they work for
POS_CODE = the position code or job code they are assigned to
EMP_COST = their total employment cost (salary)

LCTurner_1-1714458200201.png

 

 

I want to create a table called Table_CompaRatio that I can use as the basis for other calculations using DAX syntax but I cannot seem to get it to work.
I want to group by POS_CODE and display the distinct count of ORGDATA_CPY_NAME, count of UNIQ_ID and median of EMP_COST.

I also want to filter the results so it only includes rows for POS_CODEs where distinct count of ORGDATA_CPY_NAME >2 and count of UNIQ_ID >3.

I have tried multiple different ways of doing it but keep getting different errors.

I am very new to Power BI so have been using a chat GPT type AI to assist creating the syntax.

I tried this syntax:

 

Table_CompaRatio =
VAR SummaryTable =
SUMMARIZE (
'POSDATA',
'POSDATA'[POS_CODE],
"DistinctCount_ORGDATA_CPY_NAME", DISTINCTCOUNT('POSDATA'[ORGDATA_CPY_NAME]),
"Count_UNIQ_ID", COUNT('POSDATA'[UNIQ_ID]),
"Median_EMP_COST", MEDIANX (
FILTER (
ALL('POSDATA'),
'POSDATA'[POS_CODE] = EARLIER('POSDATA'[POS_CODE]) &&
DISTINCTCOUNT('POSDATA'[ORGDATA_CPY_NAME]) > 2 &&
COUNT('POSDATA'[UNIQ_ID]) > 3
),
'POSDATA'[EMP_COST]
)
)
RETURN
CALCULATETABLE (
SELECTCOLUMNS (
SummaryTable,
"POS_CODE", 'POSDATA'[POS_CODE],
"DistinctCount_ORGDATA_CPY_NAME", [DistinctCount_ORGDATA_CPY_NAME],
"Count_UNIQ_ID", [Count_UNIQ_ID],
"Median_EMP_COST", [Median_EMP_COST]
),
ALLEXCEPT('POSDATA', 'POSDATA'[POS_CODE])
)


Which brought up this error message:
"The DAX expression for calculated table 'Table_CompaRatio' results in a variant data type for column 'Median_EMP_COST'. Please modify the calculation such that the column has a consistent data type."


I have ensured that there are no blanks and all EMP_COST values are numeric.

I also tried this:

Table_CompaRatio =
CALCULATETABLE(SUMMARIZE(POSDATA,POSDATA[POS_CODE],"CPYCOUNT",DISTINCTCOUNT(POSDATA[ORGDATA_CPY_NAME]),"INCCOUNT",count(POSDATA[UNIQ_ID]),"EC_MED",MEDIAN(POSDATA[CMP_EC])),DISTINCTCOUNT(POSDATA[ORGDATA_CPY_NAME])>2, COUNT(POSDATA[UNIQ_ID])>3)


But had an error:
"The True/False expression does not specify a column. Each True/False expressions used as a table filter expression must refer to exactly one column."

I have created the output as a visualisation so I know what the data should look like:

LCTurner_2-1714458440753.png


Any help would be appreciated.




1 ACCEPTED SOLUTION

First step:  Create a table visual with implicit measures (and no totals)

 

lbendlin_0-1714520569622.png

Second step: "Borrow" the DAX code from Performance Analyzer

 

lbendlin_1-1714520615387.png

 

lbendlin_2-1714520642116.png

Last step:  cleanup

 

 

 

 

New Table = SUMMARIZECOLUMNS(
			'Table'[POS_CODE],
			"DistinctCountORGDATA_CPY_NAME", CALCULATE(DISTINCTCOUNT('Table'[ORGDATA_CPY_NAME])),
			"CountUNIQ_ID", CALCULATE(COUNTA('Table'[UNIQ_ID])),
			"MedianEMP_COST", CALCULATE(Value(MEDIAN('Table'[EMP_COST])))
		)

 

 

 

 

Optional: apply your filters to the new table.

 

Note:  There is clearly a bug in Power BI resulting in your 

"The DAX expression for calculated table 'New Table' results in a variant data type for column 'MedianEMP_COST'. Please modify the calculation such that the column has a consistent data type."

error.  I worked around it with the VALUE() cast but I shouldn't have to.  If you have a Pro license you can open a Pro ticket at https://admin.powerplatform.microsoft.com/newsupportticket/powerbi
Otherwise you can raise an issue at https://community.fabric.microsoft.com/t5/Issues/idb-p/Issues .

 

 

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

UNIQ_IDORGDATA_CPY_NAMEPOS_CODEEMP_COST
ID1Company AJob 1184975
ID2Company BJob 2171233
ID3Company BJob 2183293
ID4Company BJob 292473
ID5Company CJob 2229272
ID6Company DJob 2148892
ID7Company CJob 2204673
ID8Company BJob 2182699
ID9Company BJob 2116287
ID10Company EJob 2176553
ID11Company EJob 2239427
ID12Company CJob 3168012
ID13Company CJob 3167761
ID14Company DJob 4137955
ID15Company BJob 5245209
ID16Company EJob 6234693
ID17Company FJob 7222599
ID18Company BJob 8112344
ID19Company BJob 8113580
ID20Company BJob 8139393
ID21Company EJob 8107764
ID22Company GJob 9199456
ID23Company GJob 9130194
ID24Company FJob 978545
ID25Company FJob 9217730
ID26Company HJob 9186181
ID27Company HJob 989719
ID28Company HJob 9225200
ID29Company HJob 9123443
ID30Company HJob 995538

First step:  Create a table visual with implicit measures (and no totals)

 

lbendlin_0-1714520569622.png

Second step: "Borrow" the DAX code from Performance Analyzer

 

lbendlin_1-1714520615387.png

 

lbendlin_2-1714520642116.png

Last step:  cleanup

 

 

 

 

New Table = SUMMARIZECOLUMNS(
			'Table'[POS_CODE],
			"DistinctCountORGDATA_CPY_NAME", CALCULATE(DISTINCTCOUNT('Table'[ORGDATA_CPY_NAME])),
			"CountUNIQ_ID", CALCULATE(COUNTA('Table'[UNIQ_ID])),
			"MedianEMP_COST", CALCULATE(Value(MEDIAN('Table'[EMP_COST])))
		)

 

 

 

 

Optional: apply your filters to the new table.

 

Note:  There is clearly a bug in Power BI resulting in your 

"The DAX expression for calculated table 'New Table' results in a variant data type for column 'MedianEMP_COST'. Please modify the calculation such that the column has a consistent data type."

error.  I worked around it with the VALUE() cast but I shouldn't have to.  If you have a Pro license you can open a Pro ticket at https://admin.powerplatform.microsoft.com/newsupportticket/powerbi
Otherwise you can raise an issue at https://community.fabric.microsoft.com/t5/Issues/idb-p/Issues .

 

 

Thanks so much for the explanation.
I will raise the issue on the community page as well.

Thanks!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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