Calculate based on date sum of hours based on date

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
I have a problem that I am trying to solve. I am working on a Timecard project. I have two sheets: FWS_TimeCard which is the timecard where all the hours that are paid out and recorded; and Allocation_Table which is the source of pay rates and number of available hours.

As we can have a payrate change in the middle of a Fiscal Year, I need to adjust the available hours balance to take into account when the pay rate changes. What I am trying to figure out is how to do the following:
  1. In Allocation_Table!B14 enter Sum of hours used (Columns D & L) for each date in the FWS_TimeCard sheet (Columns C & K) if date is before Fed Work Study Spring Rate Start Date (Allocation_Table!B32), excluding any "CLOSED", "NO FWS" or any Non Numeric values.
  2. In Allocation_Table!B16 enter Sum of hours used (Columns D & L) for each date in the FWS_TimeCard sheet (Columns C & K) if date is on or after Fed Work Study Spring Rate Start Date (Allocation_Table!B32), excluding any "CLOSED", "NO FWS" or any Non Numeric values.
The FWS_TimeCard rows start on Row 17, with the first rows of dates on row 20.

My TimeCard sheet has 27 pay periods that look like the following.
000 BLANK 23-241.xlsx
ABCDEFGHIJKLMNOPQ
211
212Pay Pd 14Start:17-Dec-23End:30-Dec-23FWS Wk Days0
213Week 1Week 2
214DatesFWSDatesFWS
215Sunday17-Dec-23ClosedSunday24-Dec-23Closed
216Monday18-Dec-23Monday25-Dec-23Closed
217Tuesday19-Dec-23Tuesday26-Dec-23
218Wednesday20-Dec-23Wednesday27-Dec-23
219Thursday21-Dec-23Thursday28-Dec-23
220Friday22-Dec-23ClosedFriday29-Dec-23Closed
221Saturday23-Dec-23ClosedSaturday30-Dec-23Closed
222Total Weekly Hours0.00Total Weekly Hours0.00
223Pay Period TotalsFWS0.00
224
225
226
227Pay Pd 15Start:31-Dec-23End:13-Jan-24FWS Wk Days7
228Week 1Week 2
229DatesFWSDatesFWS
230Sunday31-Dec-23ClosedSunday7-Jan-24Closed
231Monday1-Jan-24Monday8-Jan-24
232Tuesday2-Jan-24Tuesday9-Jan-24
233Wednesday3-Jan-24Wednesday10-Jan-24
234Thursday4-Jan-24Thursday11-Jan-24
235Friday5-Jan-24Friday12-Jan-24
236Saturday6-Jan-24ClosedSaturday13-Jan-24Closed
237Total Weekly Hours0.00Total Weekly Hours0.00
238Pay Period TotalsFWS0.00
239
240
FWS_TimeCard
Cell Formulas
RangeFormula
B212,B227B212=IF(B197+1<=27, B197+1, 1)
D212,D227D212=B215
H212,H227H212=K221
N212,N227N212=SUM( IF(OR($C215="CLOSED",$C215="NO FWS"),0,IF(NOW()<=$B215,1,0)), IF(OR($C216="CLOSED",$C216="NO FWS"),0,IF(NOW()<=$B216,1,0)), IF(OR($C217="CLOSED",$C217="NO FWS"),0,IF(NOW()<=$B217,1,0)), IF(OR($C218="CLOSED",$C218="NO FWS"),0,IF(NOW()<=$B218,1,0)), IF(OR($C219="CLOSED",$C219="NO FWS"),0,IF(NOW()<=$B219,1,0)), IF(OR($C220="CLOSED",$C220="NO FWS"),0,IF(NOW()<=$B220,1,0)), IF(OR($C221="CLOSED",$C221="NO FWS"),0,IF(NOW()<=$B221,1,0)), IF(OR($L215="CLOSED",$L215="NO FWS"),0,IF(NOW()<=$K215,1,0)), IF(OR($L216="CLOSED",$L216="NO FWS"),0,IF(NOW()<=$K216,1,0)), IF(OR($L217="CLOSED",$L217="NO FWS"),0,IF(NOW()<=$K217,1,0)), IF(OR($L218="CLOSED",$L218="NO FWS"),0,IF(NOW()<=$K218,1,0)), IF(OR($L219="CLOSED",$L219="NO FWS"),0,IF(NOW()<=$K219,1,0)), IF(OR($L220="CLOSED",$L220="NO FWS"),0,IF(NOW()<=$K220,1,0)), IF(OR($L221="CLOSED",$L221="NO FWS"),0,IF(NOW()<=$K221,1,0)))
B215,B230B215=K206+1
B216:B221,K231:K236,B231:B236,K216:K221B216=B215+1
K215,K230K215=B221+1
C222,L237,C237,L222C222=SUM(C215:C221)
G223,G238G223=SUM(C222,L222)


The Allocation_Table is the following:
000 BLANK 23-241.xlsx
AB
12Federal Work Study Grant$ -
13Fed. Work Study - Sum/Fall - Hourly Rate$ -
14Fed. Work Study - Sum/Fall - Hours Used0.00
15Fed. Work Study - Spring - Hourly Rate$ -
16Fed. Work Study - Sum/Fall - Hours Used0.00
17Federal Work Study Work - Sum/Fall Hrs0
18Federal Work Study Work - Spring Hrs0
Allocation_Table
Cell Formulas
RangeFormula
B16B16=B14*B15
B17:B18B17=IF(B12>0,ROUND((B14)/B15,2),0)

000 BLANK 23-241.xlsx
AB
31Fed. Work Study - Sum/Fall Rate Start Date7/1/2023
32Fed. Work Study - Spring Rate Start Date12/31/2023
33FWS Allocation Period End5/23/2024
Allocation_Table
 
I am not understanding why you are using COUNTA(res)? I am looking for the total (sum) hours that are being charged (Columns C & L)

Ohh I was counting the days... sorry I misunderstood.
You want the FWS hours.

try this:

SumOfHours.xlsx
AB
14Sum of hours used 123
15Sum of hours used 25
Allocation_Table
Cell Formulas
RangeFormula
B14B14=LET( d,VSTACK(FWS_TimeCard!$B$20:$B$10000,FWS_TimeCard!$K$20:$K$10000), f,VSTACK(FWS_TimeCard!$C$20:$C$10000,FWS_TimeCard!$L$20:$L$10000), res,FILTER(f,IFERROR(ISNUMBER(d)*(d>DATE(2020,1,1)),0)*(d<$B$32)*ISNUMBER(f)), IFERROR(SUM(res),0) )
B15B15=LET( d,VSTACK(FWS_TimeCard!$B$20:$B$10000,FWS_TimeCard!$K$20:$K$10000), f,VSTACK(FWS_TimeCard!$C$20:$C$10000,FWS_TimeCard!$L$20:$L$10000), res,FILTER(f,IFERROR(ISNUMBER(d)*(d>DATE(2020,1,1)),0)*(d>=$B$32)*ISNUMBER(f)), IFERROR(SUM(res),0) )
 
Upvote 0
Solution

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Additionally, I am not sure I understand the res, Filter line. (I am trying to understand the LET & Filter)
 
Upvote 0
I understand that the "d" is representing the values in the B column and K column and "f" is the C & L Columns.
This is the segment that I am not understanding and how it is getting from the d & f variables.

Excel Formula:
res,FILTER(f,IFERROR(ISNUMBER(d)*(d>DATE(2020,1,1)),0)*(d<$B$33)*ISNUMBER(f)),
IFERROR(SUM(res),0)
 
Upvote 0
As you said d are columns B and K stacked vertically on each other and f is columns C and L stacked on each other.
f contains all the rows even the header and the empty ones in between data groups.
1. First we have to filter f so that we keep only the rows where the corresponding d row has a date. That is accomplished with the first part of the criteria argument:
Excel Formula:
IFERROR(ISNUMBER(d)*(d>DATE(2020,1,1)),0)

2. Then we want to filter by date d so that we keep only the ones before (or after for the second formula) the date in B32 (or B33 or where you date is). So we use this:
Excel Formula:
(d<$B$33)

3. And last we will only keep the rows that have a numeric value in f:
Excel Formula:
ISNUMBER(f)

Now you need all tree condition to be true so you apply an AND operator. You could do this:
Excel Formula:
AND( IFERROR(ISNUMBER(d)*(d>DATE(2020,1,1)),0); (d<$B$33); ISNUMBER(f) )

Or, as I did, multiply the terms (which in logical terms is the same thing):
Excel Formula:
IFERROR(ISNUMBER(d)*(d>DATE(2020,1,1)),0) * (d<$B$33) * ISNUMBER(f)

So FILTER returns only those rows of f that have a numeric value representing hours in FWS.

Last you sum them up. But if for any reason FILTER returns no value, because every row is filtered out, then you would get an error, so that's why we have the IFERROR

Hope this makes sense. If you have any doubts just ask.
 
Upvote 0
Maybe with this it make more sense:

SumOfHours.xlsx
BCDEFGHIJKLMNO
1Just a date for the example
221/06/2023
3dfIs DateDate < 21/06/2023?Is f numeric?
4Is Number?> 2000-01-01CombinedCombinedCombined
5
6asdfStart:FALSETRUEFALSEFALSEFALSEFALSEFALSE
7Week 1FALSEFALSEFALSETRUEFALSEFALSEFALSE
8DatesFWSFALSETRUEFALSEFALSEFALSEFALSEFALSE
918/06/2023ClosedTRUETRUETRUETRUETRUEFALSEFALSE
1019/06/20236TRUETRUETRUETRUETRUETRUETRUE
1120/06/20235TRUETRUETRUETRUETRUETRUETRUE
1221/06/202310TRUETRUETRUEFALSEFALSETRUEFALSE
1322/06/20231TRUETRUETRUEFALSEFALSETRUEFALSE
1423/06/2023TRUETRUETRUEFALSEFALSEFALSEFALSE
1524/06/2023ClosedTRUETRUETRUEFALSEFALSEFALSEFALSE
16FALSEFALSEFALSETRUEFALSEFALSEFALSE
17FALSEFALSEFALSETRUEFALSEFALSEFALSE
18FALSEFALSEFALSETRUEFALSEFALSEFALSE
19
20
21FILTER FUNCTION after Is DateFILTER FUNCTION after Date < 21/06/2023FILTER FUNCTION after Is f numeric?SUM
22ClosedClosed611
23665
2455
2510
261
270
28Closed
Hoja2
Cell Formulas
RangeFormula
E6:E18E6=ISNUMBER(B6)
F6:F18F6=B6>DATE(2000,1,1)
G6:G18G6=AND(E6,F6)
I6:I18I6=B6<$I$2
J6:J18,M6:M18J6=AND(G6,I6)
L6:L18L6=ISNUMBER(C6)
G22:G28G22=FILTER(C6:C18,G6:G18)
J22:J24J22=FILTER(C6:C18,J6:J18)
M22:M23M22=FILTER(C6:C18,M6:M18)
O22O22=SUM(M22:M31)
Dynamic array formulas.
 
Upvote 0
Ok Thank you. I think the Multiplication in the formula was what was confusing me.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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