Sum penalty amount for values that fall outside of a specified range

BAvant

New Member
Joined
Aug 2, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I need to identify the total penalty incurred within a 30 day period using 30 minute interval data. The 30 minute interval data values are required to be between 39-42 and if they are not a $200 penalty is incurred. The part I'm having trouble with is that if a penalty is incurred there is a 12 hour rectification period so I would need the formula to skip the next 12 hours (24 rows) then begin searching for values outside of the range again and continue adding the $200 penalty as necessary. Also, the 12 hour rectification period only accumulates during the working hours of 7am-4pm, so if a value falls outside of 39-42 at 11pm, the 12 hours would begin at 7am and end at 10am the following day.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I need to identify the total penalty incurred within a 30 day period using 30 minute interval data. The 30 minute interval data values are required to be between 39-42 and if they are not a $200 penalty is incurred. The part I'm having trouble with is that if a penalty is incurred there is a 12 hour rectification period so I would need the formula to skip the next 12 hours (24 rows) then begin searching for values outside of the range again and continue adding the $200 penalty as necessary. Also, the 12 hour rectification period only accumulates during the working hours of 7am-4pm, so if a value falls outside of 39-42 at 11pm, the 12 hours would begin at 7am and end at 10am the following day.
It may help if you provide an example of what the data would look like and the desired result in a number of scenarios. You can use the xl2bb add (link below) to paste mini workbook. If you can't use that, then please just copy and paste the data as a table. Please do not just post an image... the forum would have to completely type all the scenarios which takes time and could have typos that are not easily recognized.

Thanks in advance.
 
Upvote 0
Is your data already one value every 30 min? Like this:
DatetimeValues
01/07/2024 00:0042
01/07/2024 00:3039
01/07/2024 01:0040
01/07/2024 01:3042
01/07/2024 02:0039
01/07/2024 02:3041
01/07/2024 03:0042
01/07/2024 03:3040
01/07/2024 04:0042
01/07/2024 04:3040
01/07/2024 05:0040
01/07/2024 05:3039
01/07/2024 06:0041
01/07/2024 06:3040


Or do you have it with a higher frequency and you need to check in intervals of 30 min? That is your data is something like this:

DatetimeValues
01/07/2024 00:0039
01/07/2024 00:0342
01/07/2024 00:0641
01/07/2024 00:0941
01/07/2024 00:1242
01/07/2024 00:1540
01/07/2024 00:1840
01/07/2024 00:2140
01/07/2024 00:2440
01/07/2024 00:2741
01/07/2024 00:3040
01/07/2024 00:3340
01/07/2024 00:3640
01/07/2024 00:3939
 
Upvote 0
TimestampValuesPenalties
01-Jun-24 12:00:00 AM PDT
51.6​
01-Jun-24 12:30:00 AM PDT
52.2​
01-Jun-24 1:00:00 AM PDT
52.7​
01-Jun-24 1:30:00 AM PDT
53.1​
01-Jun-24 2:00:00 AM PDT
53.4​
01-Jun-24 2:30:00 AM PDT
53.7​
01-Jun-24 3:00:00 AM PDT
54​
01-Jun-24 3:30:00 AM PDT
54.3​
01-Jun-24 4:00:00 AM PDT
54.7​
 
Upvote 0
Current formula for C2:C25 is =IF(AND(OR(B17<39,B17>42),COUNTIF(C$2:Cx-1,200)=0),200,"")
Current formula for C26 and on is =IF(AND(OR(B18<39,B18>42),COUNTIF(C3:C25,200)=0),200,"")

The only problem with these formulas is that they do not address the issue of the 12 hour rectification period only accumulating during working hours.
 
Upvote 0
Ok here is my first try:

First formula in D3, shows all the variables used and calculated for you to check if the result is as expected. If you have any questions just ask.
And in the formula in L3 you get only the result (I understand you need, which is the total penalty count).
The example data i used has more data than just 1 value every 30 min, but the formula should work fine with just 1 value every 30 min.

Here is the working file for you to download: Penalties.zip

Try it and let me know.

Book1.xlsx
ABCDEFGHIJKL
1Days of data ->15
2DatetimeValues30 min IntervalOutside allowed bandWorking HourRectification period (dif from 0)Rec period hours countRec period startsTotal penaltiesOnly penalties count
301/07/2024 00:004101/07/2024 00:00000001111
401/07/2024 00:034001/07/2024 00:3000000
501/07/2024 00:063901/07/2024 01:00100.100
601/07/2024 00:094201/07/2024 01:30100.100
701/07/2024 00:124001/07/2024 02:00000.100
801/07/2024 00:154101/07/2024 02:30000.100
901/07/2024 00:184101/07/2024 03:00000.100
1001/07/2024 00:214101/07/2024 03:30100.100
1101/07/2024 00:243901/07/2024 04:00000.100
1201/07/2024 00:274201/07/2024 04:30100.100
1301/07/2024 00:304001/07/2024 05:00100.100
1401/07/2024 00:333901/07/2024 05:30000.100
1501/07/2024 00:364101/07/2024 06:00000.100
1601/07/2024 00:394001/07/2024 06:30000.100
1701/07/2024 00:424201/07/2024 07:00011.111
1801/07/2024 00:453901/07/2024 07:30012.120
1901/07/2024 00:484201/07/2024 08:00013.130
2001/07/2024 00:514101/07/2024 08:30014.140
2101/07/2024 00:543901/07/2024 09:00115.150
2201/07/2024 00:573901/07/2024 09:30016.160
2301/07/2024 01:003801/07/2024 10:00017.170
2401/07/2024 01:034101/07/2024 10:30018.180
2501/07/2024 01:064001/07/2024 11:00019.190
2601/07/2024 01:094201/07/2024 11:300110.1100
2701/07/2024 01:124001/07/2024 12:000111.1110
Penalty (3)
Cell Formulas
RangeFormula
A3:A7202A3=SEQUENCE(B1*24*2*10,, DATE(2024,7,1), TIME(0,3,0))
D3:J722D3=LET(dt, $A$3:$A$14402, t, FILTER(dt, dt<>""), v, FILTER($B$3:$B$14402, dt<>""), date, INT(t), time, MOD(t, 1), i, date + ROUNDDOWN(ROUND(time*24*2,1),0)/24/2, ui, UNIQUE(i), i_time, VALUE(TEXT(MOD(ui, 1), "hh:mm")), workingHour, (i_time>=VALUE("07:00"))*(i_time<VALUE("16:00")), d, BYROW(ui, LAMBDA(x, LET(d, FILTER(v, i=x), ((MAX(d)>42) + (MIN(d)<39))>0)))*1, wh_d, BYROW(HSTACK(workingHour, d), LAMBDA(x, TEXTJOIN(";",, x))), rp, DROP(REDUCE(0, wh_d, LAMBDA(arr,y, LET(wh, VALUE(TEXTBEFORE(y,";")), a, TAKE(arr,-1), b, VALUE(TEXTAFTER(y,";")), c, IF((MOD(a, 24)=0)*b, IF(wh, 1, 0.1), IF(a*(a<24), IF(wh, a+1, a), 0)), VSTACK(arr, c)))), 1), rph, ROUND(rp,0), rps, (rph=1)*1, IFERROR(HSTACK(ui, d, workingHour, rp, rph, rps, SUM(rps)), "") )
L3L3=LET(dt, $A$3:$A$14402, t, FILTER(dt, dt<>""), v, FILTER($B$3:$B$14402, dt<>""), date, INT(t), time, MOD(t, 1), i, date + ROUNDDOWN(ROUND(time*24*2,1),0)/24/2, ui, UNIQUE(i), i_time, VALUE(TEXT(MOD(ui, 1), "hh:mm")), workingHour, (i_time>=VALUE("07:00"))*(i_time<VALUE("16:00")), d, BYROW(ui, LAMBDA(x, LET(d, FILTER(v, i=x), ((MAX(d)>42) + (MIN(d)<39))>0)))*1, wh_d, BYROW(HSTACK(workingHour, d), LAMBDA(x, TEXTJOIN(";",, x))), rp, DROP(REDUCE(0, wh_d, LAMBDA(arr,y, LET(wh, VALUE(TEXTBEFORE(y,";")), a, TAKE(arr,-1), b, VALUE(TEXTAFTER(y,";")), c, IF((MOD(a, 24)=0)*b, IF(wh, 1, 0.1), IF(a*(a<24), IF(wh, a+1, a), 0)), VSTACK(arr, c)))), 1), SUM((ROUND(rp,0)=1)*1))
Dynamic array formulas.
 
Upvote 0
One thing that i didn't consider but im just thinking about is if working hours only acumulate on working days? That is from mon-fri? Or what days specifically?.
Let me know, that is an easy fix.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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