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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
DanMitieCumbria
Regular Visitor

Help to correctly write expression to calculate total standard hours worked per week

Hi, new'ish to Power BI and this is my first major model.

The model I have is to show productivity of engineers and hours they've worked.  So far this is looking ok, from the data set I have the hours worked against each job and for the various work types and this aggregates up quite nicely into weeks (i.e. week 1, week2, week 3, etc) which is how we want to see it.  And this can be seen in screen grab of the table below, which summarises hours worked by week(s) for a selected engineer:

DanMitieCumbria_0-1718116165034.png

Where I'm not happy with the report is with the column which shows the standard hours worked per week ('Std_Weekly_Hrs'). 

At present this is in the Craftperson table and is a calculated column with the expression: 

Std_Weekly_Hrs = Craftperson[Standard Hrs. avail. /day] * 5

Our data set has the standard hours available per day, (typically 8 but can be different per engineer) and as standard they work mon-fri, so 5 days per week or typical working week days.

I'd like this to total up as the other columns do, which are all measures for example:

 

1.0 Total Hours: 

1.0 Total Hours = sum('EngineerTimeRecords'[Total ActualHours]) 

or (can't decide which is best to use):

1.0 Total Hrs = CALCULATE( sum('EngineerTimeRecords'[Total ActualHours]), ALL(ProblemTypes[Request Type])) 

1.1 Reactive Hours:

1.1 Hours Reactive = CALCULATE(sum(EngineerTimeRecords[Total ActualHours]), 'ProblemTypes'[Request Type] = "Reactive") 

 

I've attempted various way to write an expression within a measure for the standard weekly hours with no success, such as:

1.6b WeeklyHours = CALCULATE(sum(Craftperson[Standard Hrs. avail. /day]), WorkingDates[WeekDay#] in {1, 2, 3, 4, 5}) 

1.6e week hours = SUMX(Craftperson, Craftperson[Standard Hrs. avail. /day] * 5)

1.7 WeeklyHours = CALCULATE(SUM(Craftperson[Standard Hrs. avail. /day]),  WorkingDates[WeekDay#] in {1, 2, 3, 4, 5})

 

Once the expression/data is sorted, this will be used in a series of charts similar to one I've created so far (but needs improved):

DanMitieCumbria_1-1718116343161.png

So is there a better way to write the expression which gives the standard weekly working hours and allows it to be totalled as the other measures are, and possibly as a measure in my '1.Calcs' table instead of the calculated column in the Craftperson table, as I have done it?

 

Relationships of the tables in the model shown below:

DanMitieCumbria_2-1718116372530.png

 

 

1 ACCEPTED SOLUTION

@Greg_Deckler  Thanks that helped to an extent, 1st made me understand an issue I wasn't aware of and 2nd led me to further investigation (youtube vids) where I came across a solution to my issue.  And from this I've managed to update the measure and table is giving the results i needed.

 

This is the measure i ended up with:

1.6 Standard Hrs. avail. /week = SUMX(VALUES(WorkingDates[WeekNo]), SUM(Craftperson[Std_Weekly_Hrs]))

And the Standard weekly hours column shows the correct value and total up as expected

DanMitieCumbria_0-1718190625360.png

 

So thanks for leading down this route of discovery

 

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@DanMitieCumbria First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  Thanks that helped to an extent, 1st made me understand an issue I wasn't aware of and 2nd led me to further investigation (youtube vids) where I came across a solution to my issue.  And from this I've managed to update the measure and table is giving the results i needed.

 

This is the measure i ended up with:

1.6 Standard Hrs. avail. /week = SUMX(VALUES(WorkingDates[WeekNo]), SUM(Craftperson[Std_Weekly_Hrs]))

And the Standard weekly hours column shows the correct value and total up as expected

DanMitieCumbria_0-1718190625360.png

 

So thanks for leading down this route of discovery

 

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors