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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

CountRows and Divide

Morning, 


We have been beating our heads againist the desk for a few days now on this problem.  Here is our table structure 

 

 

Table 1 - Employee

Table 2 - TimeEntry 

EmployeeID
FirstName
LastName
Department
 

 

EmployeeID
BilledHours
ProjectID
ProjectName

 

Basically what we are wanting to do is count the number of employees for a department from Table 1, lets say 'IT'  And then divide BilledHours in Table2 by the number of employees whose department is = IT  

 

We have tried using a measure using CountRows and it doesn't move between tables it appears.  

 

Any help would be appreciated!!! 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous

mwegener's solution may be helpful if you want to create a table visual like that.

 

Why you use a measure using CountRows doesn't work is that as a measure it calculate the current row instead of the filter content. you need to use "calculate" function to change the filter content for "countrows".

 

If you'd like the "count" or "countrows" to use in your Table 1 - Employee to calculate the count the number of employees for each department

2.png

Please create measures like

each department = CALCULATE(COUNT(Employee[EmployeeID]),ALLEXCEPT(Employee,Employee[Department]))

If you want divide BilledHours in Table2 for each EmployeeID by the number of employees per department, please create measures below

sum per id = SUM(TimeEntry[BilledHours])

divide1 = SUM(TimeEntry[BilledHours])/[each department]

3.png

 

If you want divide BilledHours in Table2 for each department by the number of employees per department, please create measures below

sum per depart = CALCULATE(SUM(TimeEntry[BilledHours]),ALLEXCEPT(Employee,Employee[Department]))

divide2 = [sum per depart]/[each department]

4.png

 

Best Regards

Maggie

View solution in original post

5 REPLIES 5
v-juanli-msft
Community Support
Community Support

Hi @Anonymous

mwegener's solution may be helpful if you want to create a table visual like that.

 

Why you use a measure using CountRows doesn't work is that as a measure it calculate the current row instead of the filter content. you need to use "calculate" function to change the filter content for "countrows".

 

If you'd like the "count" or "countrows" to use in your Table 1 - Employee to calculate the count the number of employees for each department

2.png

Please create measures like

each department = CALCULATE(COUNT(Employee[EmployeeID]),ALLEXCEPT(Employee,Employee[Department]))

If you want divide BilledHours in Table2 for each EmployeeID by the number of employees per department, please create measures below

sum per id = SUM(TimeEntry[BilledHours])

divide1 = SUM(TimeEntry[BilledHours])/[each department]

3.png

 

If you want divide BilledHours in Table2 for each department by the number of employees per department, please create measures below

sum per depart = CALCULATE(SUM(TimeEntry[BilledHours]),ALLEXCEPT(Employee,Employee[Department]))

divide2 = [sum per depart]/[each department]

4.png

 

Best Regards

Maggie

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous

If we answered your question, please mark the post as solution, this will also help others.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


mwegener
Most Valuable Professional
Most Valuable Professional

Maybe this helps...

 

Model1.pngDax1.png

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


richbenmintz
Resident Rockstar
Resident Rockstar

Hi @Anonymous

assuming you have a 1->* relationship between Table 1 and Table 2, the following should work

 

measure = divide(sum('table2'[BilledHours]), countrows('table1') )

 

Hope that helps



I hope this helps,
Richard

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

Proud to be a Super User!


Anonymous
Not applicable

@Anonymous Publish an example with some sample data of what you want and you'll get an answer in no time.

 


 


 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.