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
Syndicate_Admin
Administrator
Administrator

Multiplying Two Columns with Filters in Two Other Columns

Hello!

I'm an initiate on this subject and I'm pretty lost. Let's see if anyone can lend me a hand.

I have 2 boards:

1. Hourly Cost Per Employee Table:

EmployeeCost per employee
Javier35
Jorge32
Mary43

2. Table. Employee Hours per Project: Each employee allocates their hours to different Projects (ID_Proyecto).

ID_ProyectoAllocated HoursEmployee
231052Javier
23140Javier
23102Jorge
23148Jorge
2310267Mary
2314458Mary

I need to calculate a measure that is the labor cost per project. In the case of Project 2310 it would be equal to 52*35 + 2*32 + 267*43.

I have many more Projects and many more employees, so the solution would have to be generic (not particularized for Jorge, Javier or María).

Any ideas on where to start?

Thank you very much in advance.

1 ACCEPTED SOLUTION
jpessoa8
Continued Contributor
Continued Contributor

Hello @Syndicate_Admin ,

 

The first set to do this Calculation is to have both tabels with a relationship like the following:

jpessoa8_0-1700751898444.png

 

With this you can create 3 measures to get your result (or even get everything with only one):

First create a measure that returns the total cost per employee

 

EmployeeCost = SUM(Employee[Cost per employee])

 

 

Another measure for the Allocated Hours

 

AllocatedHours = SUM(Projects[Allocated Hours])

 

 

Now, want you want is that, for every project, to do the product of both this measures and afterwards sum all of this produtcs. For this, in DAX, you need to use a iterator function like SUMX which has as first parameter a table to iterator from, and as second parameter a calculation to be applyed to each row of that table. In your case this should be the expression:

 

 

SUMX(
	'Projects',
	[AllocatedHours] * [EmployeeCost]
)

 

 

This is the final outcome for the dataset provided 

 

jpessoa8_2-1700752517325.png

 

Here you can find a PowerBI file with this exercise : https://we.tl/t-FVD7xxpQXg


Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudo 👍
Thanks!

You can also check out my LinkedIn!

Best regards,
Jorge Pessoa

View solution in original post

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

Thank you so much @jpessoa8 !!

Now it works perfectly.

Best regards.

jpessoa8
Continued Contributor
Continued Contributor

Hi @Syndicate_Admin,

 

I've noticed that issue (I was doing the SUMX only on the ID_Proyecto level and didn't realize there could be multiple Employees in the same project) and I did an edit on my post and I don't know why it didn't reflect the changes in the Spanish Version of the community post.

 

So, what you need to change is the table input in the first parameter of the SUMX:

SUMX(
	'Projects',
	[AllocatedHours] * [EmployeeCost]
)

 

With this you will get the correct values

jpessoa8_0-1701081330385.png

Here you can find the PowerBI file with the correct version : https://we.tl/t-FVD7xxpQXg

 

For additional help, please @ me in your reply!

You can also check out my LinkedIn!

Best regards,
Jorge Pessoa

 

Syndicate_Admin
Administrator
Administrator

Hello @jpessoa8 !! How is it going?

I've been reviewing your solution and I think there's some error in the calculation and I don't really know how to solve it. I'll tell you.

  • Project 2310 labor cost: In your solution, the calculation comes out to €35,310. However, it should be the sum of Jack's labor cost (52 * 35 = 1820) + George's labor cost (2 * 32 = 64) + Mary's cost (267 * 43 = 11481). The total of this sum is €13,365 vs. €35,310.
  • Project 2314 labor cost: In Excel it costs me €19,950 (8*32 + 458 *43) and in power bi it costs €51,260.
  • Similarly, the "TotalCost" column in your power bi table adds up to 86,570 when it should be 33,315.

I get the feeling that when you filter through project 2310 or 2314 you're multiplying and adding more terms than you should.

Thanks in advance!!

Syndicate_Admin
Administrator
Administrator

Wow @jpessoa8 !! Thanks a lot!!

I've been looking at the file and it looks really good.

I'm going to test your solution in my database, which is much larger, and if I have any problems, I'll post again.

Really, thank you so much!!

jpessoa8
Continued Contributor
Continued Contributor

Hello @Syndicate_Admin ,

 

The first set to do this Calculation is to have both tabels with a relationship like the following:

jpessoa8_0-1700751898444.png

 

With this you can create 3 measures to get your result (or even get everything with only one):

First create a measure that returns the total cost per employee

 

EmployeeCost = SUM(Employee[Cost per employee])

 

 

Another measure for the Allocated Hours

 

AllocatedHours = SUM(Projects[Allocated Hours])

 

 

Now, want you want is that, for every project, to do the product of both this measures and afterwards sum all of this produtcs. For this, in DAX, you need to use a iterator function like SUMX which has as first parameter a table to iterator from, and as second parameter a calculation to be applyed to each row of that table. In your case this should be the expression:

 

 

SUMX(
	'Projects',
	[AllocatedHours] * [EmployeeCost]
)

 

 

This is the final outcome for the dataset provided 

 

jpessoa8_2-1700752517325.png

 

Here you can find a PowerBI file with this exercise : https://we.tl/t-FVD7xxpQXg


Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudo 👍
Thanks!

You can also check out my LinkedIn!

Best regards,
Jorge Pessoa

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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