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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Create column with count of entries by ID

Hi! I am relatively new to DAX, and I've been trying to replicate something like the group_by function in R. 

 

I wrote some sample data below, with the column "count" being what I need. In sum, I need to create a column (and not a table) that displays how many entries an identifier has in the sample EmployeeID column, filtered by hours > 0. Essentially I need to count the entries by ID. 

 

I tried solutions with GROUPBY that I've seen here but they output a table, and not a column. 

 

 

Employee ID HoursCount
000102
000172
000172
000241
000372
000372
000402
000422
000432

 

Thanks!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , a new column

 

countx(filter(Table, [Employee ID] =earlier([Employee ID]) && [Hours] >0 ) , [Employee ID])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Thanks @amitchandak ! problem solved

smpa01
Super User
Super User

@Anonymous  you need a measure like this

Measure =
CALCULATE (
    COUNT ( 'Table'[Hours] ),
    ALLEXCEPT ( 'Table', 'Table'[Employee ID ] ),
    'Table'[Hours] <> BLANK ()
)

 

smpa01_0-1641823287805.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

Hi @amitchandak , thank you for the quick reply! 

I tried that solution, but the output is inaccurate: the count doesn't correspond to the actual values. For instance, using the sample provided, I can see that even for IDs that only have 0 hours (which we filtered), the count is f.ex. 16, and even as the number of entries is f.ex. 4. Plus there are also some blanks. Do you know what could be wrong? 

 

Thanks again!

 

EmployeeID HoursCount
0001016
0001016

0001

0

16

0002

5

10

0002

3

10

@Anonymous ,  I tried same as new column, and did not 16 and 10 

Column = COUNTX(FILTER(Data, [EmployeeID] =EARLIER(Data[EmployeeID]) && [ Hours] >0 ), Data[EmployeeID])

 

amitchandak_0-1641822504704.png

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Sorry, I didn't express myself correctly. I meant that I tried the solution in my original dataset (which is proprietary), and the output was something like that second table I inserted. 

amitchandak
Super User
Super User

@Anonymous , a new column

 

countx(filter(Table, [Employee ID] =earlier([Employee ID]) && [Hours] >0 ) , [Employee ID])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

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.

Top Solution Authors
Top Kudoed Authors