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

Calculating on two different tables

Hi, 


I want to calculate how many rated employees we have for department A in January.

The calculation should be total working hours in table 2 = 60 / RatedHoursPrEmployee = 50 = 1,2

I have two tables related by a 1-many using an unique PK (Month+Department) on Table 1 and (Month+Department) on table 2 : 


Table 1: Table with rated hours pr employee pr department

MonthDepartmentRatedHoursPrEmployee
JanDepartment A50
JanDepartment B40
FebDepartment A

50

FebDepartment B

40

 

Table 2: Table with transactiondata on working hours pr day pr employee

DateName DepartmentWorkingHoursMonth
1. JanJohnDepartment A20Jan
2. JanJohnDepartment A20Jan
10. JanJohnDepartment A20Jan



It is possible for me to restructure table 1 as it is manually made. 

Thanks!

Mikkel

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

We can create a calculate column and a measure to meet your requirement.

 

1. Create the related column in Sickness table.

 

Related = 'Sickness'[Month] &"-"& 'Sickness'[Department]

 

ca1.jpg

 

2. Then create a relationship between Table 1 and Sickness table.

 

ca2.jpg

 

3. At last we can create a measure to get the result.

 

Measure 2 = DIVIDE(CALCULATE(SUM(Sickness[SicknessHours])) / 7.4,[Measure])

 

ca3.jpg

 

In you sample data, department A is 9 hours in month 1, so the result we get is 1.01, not the 1.97.

If you have any question, please kindly ask here and we will try to resolve it.

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

BTW, pbix as attached.

View solution in original post

4 REPLIES 4
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

In your Table 1, is there no date column, just a month column?

If yes, you can refer the following steps.

 

1. Create related columns in two tables.

 

Related = 'Table 1'[Month] &"-"& 'Table 1'[Department]
Related = 'Table 2'[Month] &"-"& 'Table 2'[Department]

 

cal1.jpg

cal2.jpg

 

2. Then create a relationship based on the Related column.

 

cal3.jpg

 

3. At last we can create a measure and the result like this,

 

Measure = 
var _x = DIVIDE(SUM('Table 2'[WorkingHours]),SUM('Table 1'[RatedHoursPrEmployee]))
return
IF(ISBLANK(_x),"null",_x)

 

cal4.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

BTW, pbix as attached.

Anonymous
Not applicable

HI @v-zhenbw-msft

Yes only a month column. I already had the related columns and that part worked fine.

The caclulated measure as well give me the desired result - thanks!

 

My next step is including a table 3 containing sickness to calculate sickness pr "measure". 

Sickness table 

MonthDepartmentSicknessHours
1Department A4
1Department A5
2Department A8
2Department B5


The result I am looking for is 1,97

By calculating total number of sick hours pr month pr department. So for department A is 17 hours sickhours in month 1. Then dividing 17 by 7,4 (hours pr day of work) = 2,3 days of sickness pr employee pr month.  

Finally calculating hours of sickness with ratedworkinghours pr employee.
2,3 / 1,2 (from previous measure) = 1,97 

My final result should be 
Month 1 = Department A is 1,97
Month 1 = Department B is xx

Month 2 = Department A is ...

 

 

Hi @Anonymous ,

 

We can create a calculate column and a measure to meet your requirement.

 

1. Create the related column in Sickness table.

 

Related = 'Sickness'[Month] &"-"& 'Sickness'[Department]

 

ca1.jpg

 

2. Then create a relationship between Table 1 and Sickness table.

 

ca2.jpg

 

3. At last we can create a measure to get the result.

 

Measure 2 = DIVIDE(CALCULATE(SUM(Sickness[SicknessHours])) / 7.4,[Measure])

 

ca3.jpg

 

In you sample data, department A is 9 hours in month 1, so the result we get is 1.01, not the 1.97.

If you have any question, please kindly ask here and we will try to resolve it.

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

BTW, pbix as attached.

amitchandak
Super User
Super User

@Anonymous , Not very clear. Create dimension of department and date and you can this formula working

 

divide(Table2[workhourmonth]),sum(Table1[RatedHoursPrEmployee]))

 

 

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
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.

Top Solution Authors