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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.