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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
forti4040
Helper III
Helper III

Column Sum * Fixed Number * Column Value

Hello,

I have a column of hours worked last year per employee and am trying to create a column for associated costs for those hours worked. I know my total spend on employee wages for last year to be $1,000 (fake number for this example). 

 

My approach has been:  Cost of Labor = ( $XX / Sum(Hours Worked) ) * Hours Worked

 

This isn't working as I believe my mixing of measures and columns is not producing the results I'm expecting.  

 

EmployeeHours WorkedCost of Labor

Bob

10??
Fred15??
Alice20??
Total45$1,000

 

I can, and have been, hardcoding the total cost of labor into my formula, but I can't figure out how to solve for the other ??'s shown above. Any help would be appreciated. 

1 ACCEPTED SOLUTION

Hi @forti4040 - Yes! You can make sure the Total Cost, Total Hours, and Cost of Labor all adjust dynamically to filters by modifying the formulas. Right now, your formula uses ALL('Employee Data')

 

Cost of Labor1 =
VAR TotalHours = CALCULATE(SUM('Table'[Hours Worked]), ALLSELECTED('Table')) -- Respects slicers
VAR TotalCost = 1000  -- Adjust this if needed to be dynamic
VAR HourlyRate = DIVIDE(TotalCost, TotalHours, 0)

RETURN SUMX('Table', 'Table'[Hours Worked] * HourlyRate)

 

rajendraongole1_0-1740075742992.png

 

 

Please find the attached pbix file. Hope this helps.





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

Proud to be a Super User!





View solution in original post

10 REPLIES 10
ArwaAldoud
Skilled Sharer
Skilled Sharer

You need to ensure the total cost is treated as a constant while dividing it by the total hours worked

TotalCost = 1000 // Replace with actual total spend

Cost of Labor =
VAR TotalHours = SUMX(ALL('Table'), 'Table'[Hours Worked])
RETURN
[TotalCost] / TotalHours * 'Table'[Hours Worked]


If this response was helpful, please accept it as a solution or give kudos to help other community members.

danextian
Super User
Super User

Hi @forti4040 

 

Can you please post your actual data, formula and your expected result?





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

@danextian since my data is proprietary I can't load it here. The example data is relatively close to what I'm working with. 

As far as expected results:
$1,000 / 45 = $22.22/hr. Then I multiply this cost by the number of hours worked on each row to get the below. 

EmployeeHours WorkedCost of Labor

Bob

10$222.22
Fred15$333.33
Alice20$444.44
Total45$1,000

 

rajendraongole1
Super User
Super User

Hi @forti4040  - You're right that mixing measures and calculated columns can cause issues. The best approach depends on whether you want this calculation to be dynamic.If you want the cost of labor to update dynamically based on filters or slicers, use a measure instead of a calculated column.

 

Cost of Labor =
VAR TotalHours = SUM('Employee Data'[Hours Worked])
VAR TotalCost = 1000 -- Replace with your actual total labor cost

RETURN
DIVIDE(TotalCost, TotalHours, 0) * SUM('Employee Data'[Hours Worked])

 

 

Check this and let know.

 

 

 

 





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

Proud to be a Super User!





@rajendraongole1 thank you for this forumla. I entered as you stated, then added Cost of Labor as a column in my table. Unfortunately I get the same value on every row of the table, which is equal to VAR TotalCost. Any thoughts on why? I tried creating this as both a measure and a column just in case I misunderstood and both produce the same result. 

I tried modifying  your formula to remove the final SUM from the hours worked, and that does produce unique values on each row when entered as a column, but the values aren't correct mathematically. 

Hi @forti4040 -create a calculated column as below:

Cost of Labor =
VAR TotalHours = CALCULATE(SUM('Table'[Hours Worked]), ALL('Table'))
VAR TotalCost = 1000  -- Replace with actual total labor cost
VAR HourlyRate = TotalCost / TotalHours

RETURN 'Table'[Hours Worked] * HourlyRate
 
 

 

 

rajendraongole1_0-1740060117311.png

 





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

Proud to be a Super User!





@rajendraongole1  & @ArwaAldoud  both of your solutions look like they work! Initially it didn't look correct because I had filters applied and the numbers were off as a result. 

That is my next question though. I need to filter the page with a few slicers and have the TotalCost, TotalHours, etc... all filtered by the same slicers. Is this possible?

 

Right now what's happening is that the $1,000 total cost is being divided by ALL values, even if I've filtered the view. I'd like the $1,000 to be divided by what's shown on the screen. 

Hi @forti4040 

 I'm happy to hear your issue was solved. Glad my solution helped as well.

Thanks for sharing your update.

Hi @forti4040 - Yes! You can make sure the Total Cost, Total Hours, and Cost of Labor all adjust dynamically to filters by modifying the formulas. Right now, your formula uses ALL('Employee Data')

 

Cost of Labor1 =
VAR TotalHours = CALCULATE(SUM('Table'[Hours Worked]), ALLSELECTED('Table')) -- Respects slicers
VAR TotalCost = 1000  -- Adjust this if needed to be dynamic
VAR HourlyRate = DIVIDE(TotalCost, TotalHours, 0)

RETURN SUMX('Table', 'Table'[Hours Worked] * HourlyRate)

 

rajendraongole1_0-1740075742992.png

 

 

Please find the attached pbix file. Hope this helps.





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

Proud to be a Super User!





@rajendraongole1 this is perfect, thank you!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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