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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
corange
Post Patron
Post Patron

Total working hours / week

Hi everyone,

 

I am new to POWER BI and I am struggling to get to where I need. I have a set of data with daily start and finish time / employee. I have calculated the duration in minutes and then converted it in decimal hours.

 

I need to show the weekly average hours and then group them into categories (less than 20 hours / week , between 20hrs and 35 hours / week, and more than 35hrs / week). I have looked in the forum to obtain the total hours / week, creating a week number column but I am lost and can't achieve what I am after.

 

Would you be able to help me.

 

Thanks in advance.

1 ACCEPTED SOLUTION
tex628
Community Champion
Community Champion

 

HOURLY BRACKETS = VAR DRIVER = DriverStartStop[Driver]
VAR WEEK = DriverStartStop[OUR NEW CREATED SUB-PERIOD]
RETURN
IF(CALCULATE(SUM(DriverStartStop[Decimal Hours Driver]), ALL(DriverStartStop), DriverStartStop[Driver]=DRIVER, DriverStartStop[weeknum]=WEEK)<20,"Less than 20hrs",
IF(CALCULATE(SUM(DriverStartStop[Decimal Hours Driver]), ALL(DriverStartStop), DriverStartStop[Driver]=DRIVER, DriverStartStop[weeknum]=WEEK)<=35,"Btw 20hrs & 35 hrs",
IF(CALCULATE(SUM(DriverStartStop[Decimal Hours Driver]), ALL(DriverStartStop), DriverStartStop[Driver]=DRIVER, DriverStartStop[weeknum]=WEEK)>35,"More than 35hrs")))

Instead of referencing the week we now want to reference the new sub period that we are using instead (P1_S1 ... P1_S2 ... and so on)

 


Connect on LinkedIn

View solution in original post

29 REPLIES 29
tex628
Community Champion
Community Champion

Hello, 

I would make a calculated column to classify each row. 

Column = 
VAR person = 'Table'[Person]
VAR week = 'Table'[Week]
return
IF(
Calculate( Sum( 'Table'[Hours] );
All( 'Table' );
'Table'[Person] = person;
'Table'[Week] = week) < 20 ; "Less than 20 Hours" ;

IF(
Calculate( Sum( 'Table'[Hours] );
All( 'Table' );
'Table'[Person] = person;
'Table'[Week] = week) <= 35 ; "Between 20 and 35 Hours" ; "More than 35 Hours" )


You might need to change your week column to a year/week column if you have dates that pass through more than one year.


Connect on LinkedIn

Hi tex628,

 

This didnt work for me. I will try to be more specific in my explanation.

 

I have got a list of employee ID with their daily starting and finish time. For each daily log, I did finish - start time using DATEDIFF to calculate duration in minutes. I have then use DATEDIFF / 60 to obtain Decimal Hour.

 

I now need to calculate the weekly ave working hours and group employees into categories <20hrs, 20hrs to 35hrs, More than 35 hrs. The graphs need to display weekly decimal hours with the legend 20hours etc... but we work by period. In a month, we have 2 periods (1st period runs from 1st to the 15, Period 2 runs from 16 to end of the month).

 

What other information would you require to be able to guide me here?

tex628
Community Champion
Community Champion

Your intensions are quite clear! 🙂 What was the result of the column i provided, did it not work at all? If possible, post a picture.

/ J


Connect on LinkedIn

Thanks for your reassurance. I am quite lost and I feel like I am overcomplicating things.

 

I have write your formula however, it didnt accept the ; so I tried with a , . It still didnt work. The attached is what I am getting. Capture.PNG

 

tex628
Community Champion
Community Champion

Replace the ; in the end with ",

Like this:
"Less than 20 hours",
instead of:
"Less than 20 hours;
image.png


Connect on LinkedIn

Thnak you. I am still having an error showing up. Am I missing something? Capture 2.PNG

thank you so much. It worked in terms of categorising the data.

 

However, I have got a little issue with regards to how I am running the billing. As advised before, I have two periods, Period 1 runs from the 1st to the 15th and Period 2 runs from the 16th to end of month. I have use a formula to get the week number and now part of the week falls under P1 and the other part falls under P2 and the results don't look right.

 

Is there a way I could have a definite cut with regards to Periods while still having a weekly average?

Capture 2 3.PNG

 

 

tex628
Community Champion
Community Champion

Well if you want to make a definite cut you are by definition changing the dates of your P1 and P2. 
For example, including week 29 in P2 in the example below will mean that you have to extend the period for P2 to include an earlier date than the 16th. 

Generally speaking, as weeks will not occur in the same pattern as your periods i would recommend that you change the measurement of your average to use a sub-period instead. 

Maybe from your P1 and P2 in July you create:
July_P1_S1,
July_P1_S2,
July_P2_S1,
July_P2_S2

With this pattern you can create the same average, not on week but on this classification instead. 

I hope you understand what im getting at!


Connect on LinkedIn

Hi,

 

I am really new so I must admit that i am a bit lost. So instead of creating a colum with a week number, I go ahead and create the colum with the pattern July_P1_S1, July_P1_S2 for each month and period and use that column in the formula you gave me for the VAR WEEK instead?

 

How would you go about getting this pattern added automatically to the table? '

 

Thank you

tex628
Community Champion
Community Champion

I would create a calculated column in the calendar table, something similar to this:

Column =
'Calendar'[Month] & "_" & 
IF(DAY('Calendar'[Date])<8 , "P1_S1" , 
IF(DAY('Calendar'[Date])<16 , "P1_S2" , 
IF(DAY('Calendar'[Date])<24 , "P2_S1" , 
IF(DAY('Calendar'[Date])<31 , "P2_S2"
))))

This should give you a column that you can use instead of the weekcolumn, try it and see if the result is suitable! 


Connect on LinkedIn

Hi,

 

Thank you for your help.

 

I have tried this but it gives me daily hours classifying everything into the <20 hours bracket. The Calendar setting i have used is the date the employees have logged in.

 

Capture4.PNGCapture5.PNG

tex628
Community Champion
Community Champion

On the measure, replace the first instance of "DriverStartStop[DriveDate]" with a month column!

image.png

If you dont have a month column, you can easily make one with a calculated column:

Column = MONTH('DriverStartStop'[DriveDate])

Connect on LinkedIn

Hi,

 

Thanks for your reply. I have tried that and it actually gave me the exact same results than what we had with the first formula. Week 29 display the results the same way. I have realised thought that they are split into the right period and adding up to a category. For example on week 29, I have 5:40 for one employee and it classify the employee in more than 35hrs for the week. which adding up with week 28 is correct. It didnt change anything.

Hi,

 

Just following up on my last message. I have tried again but it doesn't give me the right results.

tex628
Community Champion
Community Champion

This is what I wanted you to have:

MonthJuly
PeriodJuly_P1_S1July_P1_S2July_P2_S1July_P2_S2
ID121122221
ID222312115
ID331414142
ID412212312
ID541114142


You cant combine weeks with your periods, you need to use a custom subperiod and not use week at all if you want this to work.


Connect on LinkedIn

Hi tex628,

 

I have created a month column as advised and then replace drivedate with that month column as suggested but it didn't change anything for me. It is grouped the same way. I do obtained the table the way you have presented in your last answer. However, I have a number in front instead of simply having P1_S1 etc... and one display the month number and doesnt group it into the categories P1_S1 etc... as intended. We obtain the same results than before.

 

I have missed something?Capture.PNG

 

tex628
Community Champion
Community Champion

The blank ones are my misstake, 

Column =
'Calendar'[Month] & "_" & 
IF(DAY('Calendar'[Date])<8 , "P1_S1" , 
IF(DAY('Calendar'[Date])<16 , "P1_S2" , 
IF(DAY('Calendar'[Date])<24 , "P2_S1" , 
IF(DAY('Calendar'[Date])<=31 , "P2_S2"
))))

I missed a "=" on the last IF statement. 

But if we take the first week (P1_S1) in July, what is the desired result?




Connect on LinkedIn

Hi,

I have just sent the email and figued it out after clicking sent. I have modified my formula and now it does include the dates bracket correctly. So for each P1_S1 & P1_S2 i have the correct number of hours for the bracket. However, i do not wish to present the results that way. I need the total of the period.

 

The issue with the first option we worked with was that it was splitting one day (etc... 29 e.g.) and then including part of the results in to P1 the other into P2. Now, we have the correct split but I can't display the results as the total of the period. Do I make sense?

tex628
Community Champion
Community Champion

I understand! 🙂 

I'm not quite sure if this works but check if you can toggle subtotals on column level, 

image.png



Connect on LinkedIn

Hi tex628,

 

I am really sorry but I keep on facing little issues with this one.

 

i have group the row to obtain total and I am wondering if I could only display the total and have something say P1 with the month above.

 

i have this option avaible and I thought the results was not matching the results of our new formua P1_S1 etc... Turns out that when I added the total with that new formula, the system also shows a total of 6 while the distinct count for the table shows 7 as well as the ID details. Capture.PNG

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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