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

Show worked hours based on Start and End date parameters

So I have 2 tables:

  • A calendar one, which I intend to use for filtering
  • A table with employee names, when they started/ended working (some may still be working), and the hours they have worked so far

Untitled.png

My end goal would be to have a date slicer (using the calendar table) + a filter for the employee name, that would give me the worked hours between those 2 given dates

I think it may not be that hard, but I am just stuck and also could not find a related post about this.

Thank you! 

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi,@andrebarrande 

 

You can try the following methods.

1. Create a new calculation column End Date2. If there is an end date, return the end date. If there is no end date, return today's date.

End Date2 = 
IF ( 'Worked hours'[End Date] = BLANK (), TODAY (), [End Date] )

vzhangti_0-1636005671190.png

 

2.Create a calendar table as shown in the figure.

Table =
CALENDAR (
    MINX ( 'Worked hours', [Start Date] ),
    MAXX ( 'Worked hours', [End Date2] )
)

vzhangti_1-1636005884485.png

 

3.Create the measure Worked hours to calculate the working hours excluding weekends.

Worked hours = 
var _ma = max('Table'[Date])
var _mi = MIN('Table'[Date])
var _c = CALENDAR(_mi,_ma)
var _a = countrows(filter(ADDCOLUMNS(_c,"aa",WEEKDAY([Date],2)),[aa]<6))*8
return
_a

vzhangti_2-1636006142343.png

vzhangti_3-1636006197832.png

Best Regards,

Charlotte Zhang

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

Anonymous
Not applicable

Hi @v-zhangti  I appreciate you taking the time!

Unfortunately that does not solve my issue because the formula

  1. Assumes everyone is still working (For example, for Robert who stopped working in July, we would need to not count hours for him if the Date is higher than that
  2. Assumes everyone works 8 hours a week (In the example I provided you can see that, for example, Paul works 37.5 hours a week)
amitchandak
Super User
Super User

@Anonymous , Try a measure like

 

Work hour=
var _max1 = maxx(allselected('Date'), 'Date'[Date]) //selected date
var _max2 = Max(Table[End Date])
var _max = min(_max1, _max2)
return
sumx(values(Table[employee name]) , COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Min(Table[Start Date]),_max),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1))*8 )

 

 

Anonymous
Not applicable

Thank you @amitchandak 

 

It is working perfectly when I move the End Date on the slicer, but it doesn't seem to react when I move the Start Date

 

For example: This person worked from March 1st to September 5th. Total worked hours is 1080 and the formula is doing it correctly

1.JPG

If I move the End Date, it is reacting accordingly

2.JPG

But if I move the Start Date, it doesn't react

3.JPG

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.