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
Anonymous
Not applicable

Distinct count a field based on a criteria on another columns' aggregation

Hi PowerBI experts! How do you distinct count a field based on a criteria on another columns' aggregation?


example:

StaffID  Score
10156
10143
10212
10115
10343
10431
10425
10219
10123
10116

 

Desired output:
Distinct Count of StaffID where Average of Score is greater than or equal to 20.


Thanks in advance

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Anonymous,

 

Try this measure. The VALUES function returns distinct StaffID, enabling COUNTROWS to return distinct count.

 

Distinct Count StaffID = 
VAR vTable =
    ADDCOLUMNS (
        VALUES ( Table1[StaffID] ),
        "@Average", CALCULATE ( AVERAGE ( Table1[Score] ) )
    )
VAR vResult =
    COUNTROWS ( FILTER ( vTable, [@Average] >= 20 ) )
RETURN
    vResult

 

DataInsights_0-1671461539865.png

 





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @Anonymous 

 

you can also create a measure with this:

 

Avg20PlusCount = 
VAR _table =
ADDCOLUMNS(
    VALUES(TableName[StaffID]),
    "ScoreAvg",
    CALCULATE(AVERAGE(TableName[Score]))
)
RETURN
COUNTROWS(
    FILTER(
        _table,
        [ScoreAvg]>=20
    )
)

 

it worked like this:

FreemanZ_1-1671504332032.png

DataInsights
Super User
Super User

@Anonymous,

 

Try this measure. The VALUES function returns distinct StaffID, enabling COUNTROWS to return distinct count.

 

Distinct Count StaffID = 
VAR vTable =
    ADDCOLUMNS (
        VALUES ( Table1[StaffID] ),
        "@Average", CALCULATE ( AVERAGE ( Table1[Score] ) )
    )
VAR vResult =
    COUNTROWS ( FILTER ( vTable, [@Average] >= 20 ) )
RETURN
    vResult

 

DataInsights_0-1671461539865.png

 





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

Proud to be a Super User!




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.