Hi Pofski,
Before we go over the formulas, let me start with the approach I used for the calculation.
To determine the hours for a person for a specific period of time, we will first need to determine how many days overlap with the selected period.
Let us use an example:
- Assume the period of interest is June 1 to June 5
- John worked May 15 to June 11 (which is 20 working days) for a total of 40 hours.
- This means that John worked 40 hrs / 20 days = 2 hrs/day.
- The number of working days between June 1 and June 5 is 3 days.
- That means that John's hours for June 1 to June 5 is 3 days * 2 hrs/day = 6 hours.
The above approach works when working with a single row of data. When working with multiple rows of data, we will need to tweak our approach as follows:
- First determine the total time period where John was scheduled for work. This would be the minimum date of all the start dates, to the maximum of all due dates. (With the supplied data, this becomes May 6 to June 14)
- Then determine the number of days in each work assignment that overlaps with the Total Time Period.
- Divide the estimated hours for each work assignment by the number of overlapping days for each work assignment to get the hours per day.
- Then determine the number of days of overlap between the time period of interest (say June 10-June 14) and the Total Time Period (May 6-June 14)
- Multiple results from [4] with the results from [3]
Now let us examine the formulas:
- To calculate the minimum of all start dates for John we can use =MIN(IF(Translator=L2, StartDate)) where L2 refers to "John"
- To calculate the maximum of all due dates for John we can use =MAX(IF(Translator=L2, DueDate)) where L2 refers to "John"
- This allows us to calculate the working dates (let us refer to it as "Total Time Period for John") between the MIN and MAX dates, using the following formula:
WORKDAY(O15,ROW(OFFSET(A$1,,,NETWORKDAYS(O15,P15)-1)))
Here O15 is the MIN date, and P15 is the MAX date.
4. Next we need to calculate the overlap between the startdate and due date for each assignment. Using the named ranges called "StartDate" and "DueDate", this then becomes the following comparison:
(TRANSPOSE(WORKDAY(O15,ROW(OFFSET(A$1,,,NETWORKDAYS(O15,P15)-1))))>=StartDate)*(TRANSPOSE(WORKDAY(O15,ROW(OFFSET(A$1,,,NETWORKDAYS(O15,P15)-1))))<=DueDate)
This returns a value of 1 where there is a date overlap, and zero if not.
5. MMULT can then be used to add up each row in this array to get a result array like {2;4;0;5} indicating that the first assignment has 2 days, second has 4 days, etc.
6. Next we divide the estimated hours for each assignment by the above array. Using the named range "Estimate", this becomes the following:
Estimate/MMULT(...)
7. We need to do a similar calculation to determine the number of days of overlap between the Total Time Period for John and the specific time period of interest (say June 10-June 14)
We then multiply the results from [6] and [7], and then SUM it to get the final result.
Putting it all together, we get the following formula:
=SUM(IFERROR(Estimate/MMULT((TRANSPOSE(WORKDAY(O15,ROW(OFFSET(A$1,,,NETWORKDAYS(O15,P15)-1))))>=StartDate)*(TRANSPOSE(WORKDAY(O15,ROW(OFFSET(A$1,,,NETWORKDAYS(O15,P15)-1))))<=DueDate), ROW(OFFSET(A$1,,,NETWORKDAYS(O15,P15)-1))^0),0) * MMULT((TRANSPOSE(WORKDAY(M15,ROW(OFFSET(A$1,,,NETWORKDAYS(M15,N15)-1))))>=StartDate)*(TRANSPOSE(WORKDAY(M15,ROW(OFFSET(A$1,,,NETWORKDAYS(M15,N15)-1))))<=DueDate), ROW(OFFSET(A$1,,,NETWORKDAYS(M15,N15)-1))^0))
I am sure this can be simplified further. But hope it helps you in understanding the above approach and formula.
Cheers,
Sajan.