Formula to calculate working hours in a reference period

TaxSloth

New Member
Joined
Oct 25, 2022
Messages
11
Office Version
  1. 2021
Platform
  1. MacOS
So we do a lot of work that involves calculating how many IRS working hours an employee qualifies for in a given year / employment window. Essentially, it's 8 hours for every weekday in the year that they work. What I'm trying to create is a quick formula that can reference a date range using a Start Date value from one cell and an End Date value in another cell. So if it's say 4/1/2020 and 11/15/2020, I want it to report back a total of 8 hours per weekday in that period.

My current plan is to create an index with three columns - Date, Day, Hours - and basically prefill out a chart with 8 hours on qualified days, and then sum values in a range from that Start Date cell to the End Date cell. What I can't figure out is how to search for say cell A2's content in a separate sheet like vlookup, but instead of returning the value in index 3 of the array I want it to report back the cell name of that cell in the third column so I can use it in a SUM formula. That way I can SUM the values between Start Date and End Date on my table directly. This will let me put an Active row at the very end of the table to account for employees who work through the full year, since current employees don't have End Dates.

Below is a rough example of the index I'm working from, since I can't upload a direct workbook on the mac. I can't figure out a formula that I can use to reference the start and end dates provided and sum the values for those dates according to my index table. Alternate suggestions for how to accomplish this are welcome, but ideally help with the formula I need is preferred.

Start DateEnd DateTotal Hours
1/1/20201/6/2020XX
1/6/2020ActiveXX

DateDayHours
1/1/2020=text(A2,"ddd")8
1/2/2020|8
1/3/2020|8
1/4/2020|8
1/5/2020|8
1/6/2020|0
1/7/2020|0
1/8/2020|8
ACTIVEV0
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Keep an eye on your start and end dates, you have the same date as the end of the first row and the start of the second. Doing this will cause any hours on those dates to be included in both.
The end date in the first row should be the last day for that period and the start date in the next row should be the first day for that period.

21-11-22.xlsx
ABCDEFG
1DateDayHoursStart DateEnd DateTotal Hours
201/01/2020Wed801/01/202006/01/202040
302/01/2020Thu806/01/2020Active8
403/01/2020Fri8
504/01/2020Sat8
605/01/2020Sun8
706/01/2020Mon0
807/01/2020Tue0
908/01/2020Wed8
10ACTIVE0
Sheet4
Cell Formulas
RangeFormula
G2G2=SUMIFS(C:C,A:A,">="&E2,A:A,"<="&F2)
G3G3=SUMIFS(C:C,A:A,">="&E3,A:A,IF(ISNUMBER(F3),"<="&F3,"<>0"))
B2:B9B2=TEXT(A2,"ddd")
 
Upvote 0
Solution
What are work days?
Are holidays included?
I have included a small example; this can be simplified.

T202211.xlsm
ABCDEFG
1Date1-Apr-2230-Apr-22164Min Hours
229-Mar-228TRUE8
330-Mar-228TRUE8
431-Mar-2210TRUE8
51-Apr-228TRUE8
62-Apr-228FALSE8
73-Apr-228FALSE8
84-Apr-224TRUE4
95-Apr-2210TRUE8
106-Apr-228TRUE8
117-Apr-228TRUE8
128-Apr-228TRUE8
139-Apr-228FALSE8
1410-Apr-228FALSE8
1511-Apr-228TRUE8
1612-Apr-228TRUE8
1713-Apr-2210TRUE8
1814-Apr-228TRUE8
1915-Apr-228TRUE8
2016-Apr-228FALSE8
2117-Apr-2210FALSE8
2218-Apr-228TRUE8
2319-Apr-228TRUE8
2420-Apr-228TRUE8
2521-Apr-228TRUE8
2622-Apr-2210TRUE8
2723-Apr-228FALSE8
2824-Apr-228FALSE8
2925-Apr-228TRUE8
3026-Apr-228TRUE8
3127-Apr-228TRUE8
3228-Apr-2210TRUE8
3329-Apr-228TRUE8
3430-Apr-228FALSE8
351-May-228FALSE8
362-May-228TRUE8
2a
Cell Formulas
RangeFormula
F1F1=SUMPRODUCT(--(A2:A36>=D1),--(A2:A36<=E1),--(F2:F36=TRUE),G2:G36)
F2:F36F2=WORKDAY.INTL(A2-1,1,1)=A2
G2:G36G2=MIN(C2,8)
 
Upvote 0
Keep an eye on your start and end dates, you have the same date as the end of the first row and the start of the second. Doing this will cause any hours on those dates to be included in both.
The end date in the first row should be the last day for that period and the start date in the next row should be the first day for that period.

21-11-22.xlsx
ABCDEFG
1DateDayHoursStart DateEnd DateTotal Hours
201/01/2020Wed801/01/202006/01/202040
302/01/2020Thu806/01/2020Active8
403/01/2020Fri8
504/01/2020Sat8
605/01/2020Sun8
706/01/2020Mon0
807/01/2020Tue0
908/01/2020Wed8
10ACTIVE0
Sheet4
Cell Formulas
RangeFormula
G2G2=SUMIFS(C:C,A:A,">="&E2,A:A,"<="&F2)
G3G3=SUMIFS(C:C,A:A,">="&E3,A:A,IF(ISNUMBER(F3),"<="&F3,"<>0"))
B2:B9B2=TEXT(A2,"ddd")
I think there's been a misunderstanding when it comes to my example. The two separate rows are entirely distinct and separate employees, and were just an example to demonstrate what I need the formula to be able to handle. There's no concern of overlapping dates there, and having to use a distinct separate formula for any employee currently marked Active would defeat the purpose entirely. I need a single formula I can use for each employee so that it will provide the total hours for that range of dates, referencing the start and end dates to set the sum range. The G2 formula I can potentially use to plug in as needed to solve the math on specific instances of employees that work for a portion of the year, but it's not ideal to have a bank of problem solving formulas I have to cycle between here.
 
Upvote 0
What are work days?
Are holidays included?
I have included a small example; this can be simplified.

T202211.xlsm
ABCDEFG
1Date1-Apr-2230-Apr-22164Min Hours
229-Mar-228TRUE8
330-Mar-228TRUE8
431-Mar-2210TRUE8
51-Apr-228TRUE8
62-Apr-228FALSE8
73-Apr-228FALSE8
84-Apr-224TRUE4
95-Apr-2210TRUE8
106-Apr-228TRUE8
117-Apr-228TRUE8
128-Apr-228TRUE8
139-Apr-228FALSE8
1410-Apr-228FALSE8
1511-Apr-228TRUE8
1612-Apr-228TRUE8
1713-Apr-2210TRUE8
1814-Apr-228TRUE8
1915-Apr-228TRUE8
2016-Apr-228FALSE8
2117-Apr-2210FALSE8
2218-Apr-228TRUE8
2319-Apr-228TRUE8
2420-Apr-228TRUE8
2521-Apr-228TRUE8
2622-Apr-2210TRUE8
2723-Apr-228FALSE8
2824-Apr-228FALSE8
2925-Apr-228TRUE8
3026-Apr-228TRUE8
3127-Apr-228TRUE8
3228-Apr-2210TRUE8
3329-Apr-228TRUE8
3430-Apr-228FALSE8
351-May-228FALSE8
362-May-228TRUE8
2a
Cell Formulas
RangeFormula
F1F1=SUMPRODUCT(--(A2:A36>=D1),--(A2:A36<=E1),--(F2:F36=TRUE),G2:G36)
F2:F36F2=WORKDAY.INTL(A2-1,1,1)=A2
G2:G36G2=MIN(C2,8)

In 2020 there are 2096 qualifying work hours in the year - it's 8 hours per weekday in a given year. The problem I'm trying to solve is a formula that can calculate how many hours an employee is allocated if they happen to start late in the year or end early. I've included a link to the calculator we normally use to solve these issues so you can see what I'm trying to shortcut into a formula.

My current idea is creating a table for these workdays like I originally posted and using some formula to reference input start and end dates - then summing those applicable hours. I can't figure out a way to essentially vlookup that date on my chart and then reference the cell for that row's hour column as the start/end boundary of a sum(XX:XX) formula. So it would ideally search for the Start Date in column 1, then return the cell name of that row's C cell so I can use it as part of a Sum formula. If that's not a possibility, I'm open to alternate suggestions - but it needs to be a consistent, single formula that can handle date values or the Active value. Anything that requires direct changing for every unique employee would be more time consuming than just using the web link calculator.
 
Upvote 0
You don't need the formula in G2, the one in G3 serves both purposes. I just forgot to copy it back up to the row above after making the edit for it to work with "Active"
 
Upvote 0
You don't need the formula in G2, the one in G3 serves both purposes. I just forgot to copy it back up to the row above after making the edit for it to work with "Active"
Oh hell, I didn't test that one properly - it works perfectly, I think this will definitely solve it. Thank you!
 
Upvote 0
Actually I've run into a new problem that I didn't consider - these are going to be for specific years, obviously, but employee start or end dates might not be within that single year. So what I need is for the formula to substitute start dates from previous years as 1/01/20, for example. So hypothetically I'm doing hours for year 2020, but their Start date is 5/20/19 and they're Active - I want it to calculate as if they start 1/01/20. Included below is the actual version of the formula I'm using in the spreadsheet based on your suggestion - can you make the change to adjust dates in a prior year to calculate as if they're 1/01/20?

=SUMIFS(Sheet1!C:C,Sheet1!A:A,">="&'Qualified Labor Calc'!D4,Sheet1!A:A,IF(ISNUMBER('Qualified Labor Calc'!E4),"<="&'Qualified Labor Calc'!E4,"<>0"))
 
Upvote 0
My post did not showup; internet issues.
I am not from the USA; I do not know your rules and you did not answer my questions.
I apologize for posting. I should not have wasted my time.
I prepared an example. You can edit it for the relevant periods.
T202211.xlsm
ABCDE
1Start1-Apr-22
2End30-Apr-22
3156168
4Date
529-Mar-2288
630-Mar-2288
731-Mar-22108
8Fri 01-Apr-2288
9Sat 02-Apr-2280
10Sun 03-Apr-2280
114-Apr-2244
125-Apr-22108
136-Apr-2288
147-Apr-2288
158-Apr-2288
169-Apr-2280
1710-Apr-2280
1811-Apr-2288
1912-Apr-2288
2013-Apr-22108
2114-Apr-2288
2215-Apr-2288
2316-Apr-2280
2417-Apr-22100
2518-Apr-2244
2619-Apr-2244
2720-Apr-228
2821-Apr-2288
2922-Apr-22108
3023-Apr-2280
3124-Apr-2280
3225-Apr-2288
3326-Apr-2288
3427-Apr-2288
3528-Apr-22108
3629-Apr-2288
3730-Apr-2280
381-May-2280
392-May-2288
2a
Cell Formulas
RangeFormula
D3D3=SUMIFS(E5:E39,A5:A39,">="&D1,A5:A39,"<="&D2)
E3E3=SUMPRODUCT(--(A5:A39>=D1),--(A5:A39<=D2),--(WEEKDAY(A5:A39,2)<6))*8
E5:E39E5=(WEEKDAY(A5,2)<6)*MIN(C5,8)
 
Upvote 0
So what I need is for the formula to substitute start dates from previous years as 1/01/20, for example.
Could you post a visual with the problem in the same way that you did in post 1?

In my mind, it should be obvious what you mean but I'm just not able to visualise it at the moment.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,853
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top