Forum Discussion
Overtime Report Help
- 2 years ago
AppleMan ,
Various ways this can be done. I have attached an updated pbix that shows one of these ways.
Import your Holiday Table. Connect it to your Date Table. It should be 1-1 relationship.
Then I created a Calculated Column in your Date Table using SWITCH and LOOKUPVALUE.
I structured it to give you 0's and 1's, but you can replace these with other values if you so choose ("Holiday" or "Work Day").
Let me know if you run into any issues....
Regards and Good Luck
Hi!
Happy Friday!
I need help with hopefully one last thing. My OT is calculating exactly how I want, except for employees who work the "weekend" shift where OT is calculated daily when they go over 8 hours. It works fine for a single employee however I am testing out my measure to make sure it works for multiple employees and running into an issue.
This is what runs my OT calculation. If you look in the _OvertimeWeekend variable, youll notice that it multiplies the end part by 3. This is just temporary since the weekend overtime employee im testing with had "weekend" shifts in 3 days, or to be more clear he worked on 3 seperate days where on each day if he had more than 8 hours summed it was considered overtime.
I am trying to think of a good way to have this measure accomplish what I want and I have not been able to. I will give you an example:
| Jim | 1/28 | 11.05 | Weekend |
| Jim | 2/2 | 8.65 | Weekend |
| JIm | 2/3 | 5.08 | Weekend |
| Bob | 1/29 | 7.5 | Weekend |
| Bob | 1/29 | 1.5 | Weekend |
In this example, I would need that _OvertimeWeekend variable to return for Jim, (11.05 - 8 = 3.05) + (8.65 - 8 = .65) = 3.7 for overtime hours. For Bob, return (7.5 + 1.5) - 8 = 1 hours for overtime. If I had a card showing the total for this week range it would return 4.7 hours overtime.
The issue I am running into in my measure is dynamically getting that 3 I mentioned before to instead change to the number of days someone has hours, which works perfect for Jim, but would also throw Bobs overtime hours off since his would multiply by 3 and he worked only a single day. If I can figure out how to get these weekend, or shift 41 as you can see in my measure, workers overtime to calculate correctly then the rest of this report should go smoothly.
If you see any flaws with how im calculating this in general I am happy to take critism.
I appreciate any help, thank you!
AppleMan ,
Unable to examine this in any detail until Monday, but if you look at the file I sent you, I calculate OT separately for Saturday and Sunday in the WeekendOT measure
WeekendOT_Total =
VAR _SatHours = CALCULATE( SUM(AMTable[Hours] ),
ALLEXCEPT( DIM_Date, DIM_Date[Date] ),
DIM_Date[DayName] = "Saturday" )
VAR _SatOT = IF( _SatHours > 8, _SatHours - 8, 0 ) //Calculate OT Hours
VAR _SunHours = CALCULATE( SUM(AMTable[Hours] ),
ALLEXCEPT( DIM_Date, DIM_Date[Date] ),
DIM_Date[DayName] = "Sunday" )
VAR _SunOT = IF( _SunHours > 8, _SunHours - 8, 0 ) //Calculate OT Hours
RETURN
_SatOT + _SunOT
This ensures that OT is calculated only if employee works greater than 8 hours on a specific day.
I think this is where you are indicating troubles. Replace your _Overtime Weekend variable with my variation and see if that works towards solving your issue.
If not, we will examine in more detail next week.
Enjoy the weekend!
- AppleMan2 years agoHelper III
I did see the way you did it, the only issue is mine is not going specifically by saturday/sunday. It just goes off an employee clocking in to shift "41". This means ive seen it fall on Mondays, tuesdays, etc, dont ask me how that is possible lol.
I will continue to troubleshoot till the end of the day here on a solution that may work for my data.
- rsbin2 years agoCommunity Champion
AppleMan ,
Good Morning. In this case, my approach would be to create a new Calculated Table which creates a summary of your Shift 41 (Weekend) Hours. Group by Employee, Group by Date and Sum Hours so you get a Total for each Employee for each separate day. So your above sample table above would be 4 records and not 5. Then create a new Calculated Column to get OT as I described in one of my earlier posts above. Then you have a way to easily get your Total Weekend OT.
After you get this working then you can spend time to get your other formula above working properly. But I think it would entail creating a virtual table within your VAR _OvertimeWeekend, which takes some practice to get working properly and to account for various scenarios.Hope you understand this approach and it is to your liking.
Best Regards,
- AppleMan2 years agoHelper III
My summary table is working excellently. Groups exactly how you described and I also added a custom column that calculates the overtime for each employee. Now I am going to see if I can implement this into the above measure I shared to accurately get all overtime for employees, this should be the tricky part, using virtual tables.
- rsbin2 years agoCommunity Champion
AppleMan ,
You don't need to incorporate this into your Measure above.
Just create a simple measure called WeekendOT = SUM( YourOTTable[OTHours] ).Your first measure is WeekdayOT.
Then for Overtime_Total = [WeekdayOT] + Weekend[OT]
The idea behind creating the calculated table was to avoid messing with your Variables.
Hope I have explained this properly.
- AppleMan2 years agoHelper III
Yeah thats how I ended up doing it. Have a few more kinks to work out to get this working properly with a holiday schedule table I have to change the overtime threshhold, but all in all its coming together well.
- AppleMan2 years agoHelper III
I got a question for you in line with the switch statement you helped me with for holidays the other day. Right now, it will display a 1 on the day of the holiday. So for example, if 1/30 was a holiday, in the date table the holiday column will have a 1 on that day. I want to add another column to my date table called "Holiday Week", which displays a 1 not only on 1/30, but all days of that week that the holiday falls on. So 1/28 - 2/3 would have a 1 for this column.
Is there a simple way to adapt the switch statement to do this, or a better way?
- rsbin2 years agoCommunity Champion
AppleMan ,
Please try this as a Calculated Column in your Date table
HolidayWeek = SWITCH( TRUE(), CALCULATE( SUM( DIM_Date[CompanyHolidays] ), ALLEXCEPT( DIM_Date, DIM_Date[Year-WeekNumber_Sunday] )) = 1, 1, 0 )You can switch out the column [Year-WeekNumber_Sunday] to your relevant column. Could be your [WeekStart_Sun] column.
I made a SWITCH statement to account for those weeks that may have 2 holidays (i.e. US Thanksgiving). If you don't care for this, you can just use the CALCULATE statement. Any weeks containing a Holiday will be > 0.DateKey Date Year-WeekNumber_Sunday PayWeekStart_Sun PayWeekEnd_Sat CompanyHolidays HolidayWeek 20240706 07/06/2024 2024-27 06/30/2024 07/06/2024 0 1 20240705 07/05/2024 2024-27 06/30/2024 07/06/2024 0 1 20240704 07/04/2024 2024-27 06/30/2024 07/06/2024 1 1 20240703 07/03/2024 2024-27 06/30/2024 07/06/2024 0 1 20240702 07/02/2024 2024-27 06/30/2024 07/06/2024 0 1 20240701 07/01/2024 2024-27 06/30/2024 07/06/2024 0 1 20240630 06/30/2024 2024-27 06/30/2024 07/06/2024 0 1 20240203 02/03/2024 2024-05 01/28/2024 02/03/2024 0 1 20240202 02/02/2024 2024-05 01/28/2024 02/03/2024 0 1 20240201 02/01/2024 2024-05 01/28/2024 02/03/2024 0 1 20240131 01/31/2024 2024-05 01/28/2024 02/03/2024 0 1 20240130 01/30/2024 2024-05 01/28/2024 02/03/2024 1 1 20240129 01/29/2024 2024-05 01/28/2024 02/03/2024 0 1 20240128 01/28/2024 2024-05 01/28/2024 02/03/2024 0 1
Hope this works for you - AppleMan2 years agoHelper III
I changed the original Holiday column to text, and altered the original switch statement to display the name of the holiday rather than 1 as below:
So to make the switch statement for HolidayWeek work I changed it from summing that column to counting it (looking for holiday count above 0).
However I must not fully understand this logic here, since it is not working as intended:
- rsbin2 years agoCommunity Champion
AppleMan ,
Change "COUNT" to "COUNTA". This is how DAX counts text values.
I suggest to change your Condition from "=1" to ">=1" to take into account weeks having more than 1 holiday unless you are absolutely sure there is no week having more than 1 holiday
Hope this works!
- AppleMan2 years agoHelper III
I planned to change it to >=1 for just that reason, but COUNTA partially did it! I knew thats how that worked too.. cant you tell its Monday.
The issue im seeing is this calculated column is throwing a 1 for every single row currently.
Only days/weeks with holidays:
Column calculation for verification:
- AppleMan2 years agoHelper III
You can ignore my last response, I realized the fault in my logic is it is counting the text field and since the "0"'s are considered text it was always above 0. I added a clause in the calculate function to exclude any lines that have a holiday of "0".
- AppleMan2 years agoHelper III
I apologize for bombarding you with a million questions, but I have another one if you dont mind helping.
I set up that field we spoke about previously in the date table to give the number of holidays in that week, or 0 if none, like below:
I have decided to tally all overtime in seperate summarized tables so that I can just sum the columns necessary. What I need to do is have the overtime threshold adjust itself properly based on holiday number in that week, so week 317 would have a threshhold of 24 (40 - (2 holidays * 8)), and week 319 should have a threshhold of 32 respectively.
What is the best way to write this dax formula to adjust according to what week the data falls in?
Overall table structure in case its helpful:
- AppleMan2 years agoHelper III
What is the final variable '[fullweeknum]' in reference to?
I am not able to try this formula as its typed. I can enter everything as you show except that last variable to test it.
- AppleMan2 years agoHelper III
I found my issue, I still had the whole function wrapped in calculate. I removed that and this seems to work how I want! Thank you!