Sum data between specific day and opening/closing times

Thoron6

New Member
Joined
Oct 27, 2015
Messages
27
OK so I think I'm making this more complicated than it should be...

I have a list of data like the below (Table 2) and a separate table with the code opening and closing times which vary by day of the week (Table 1).


I'm looking to get a list of unique codes with the totals falling between the opening and closing times and a separate column for data that falls outside the opening and closing times each day. Eg.

Code | Total between times/day | Total outside of opening times.
123 xxx xxx
456 xxx xxx

Any help with the formula would be greatly appreciated.

Thanks

Table 1
Code
Mon
Tue
Wed
Thur
Fri
Sat
Sun
Mon
Tue
Wed
Thur
Fri
Sat
Sun
123
10:00
10:00
10:00
10:00
10:00
09:00
16:00
22:00
22:00
22:00
22:00
23:00
23:30
22:00
456
10:00
10:00
10:00
10:00
10:00
09:00
11:00
22:00
22:00
22:00
22:00
23:00
23:30
22:00
789
11:00
11:00
11:00
11:00
11:00
09:00
12:00
22:00
22:00
22:00
22:00
23:00
23:30
22:00

<tbody>
</tbody>


Table 2
Code
Day
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
123
Mon
2.6
2.6
2.8
1.8
1.7
2.0
3.1
4.2
1.7
123
Tue
2.3
3
6
7
7
8
11
10
7
123
Wed
2
4
5
7
8
7
15
8
2
456
Mon
3
4
5
9
8
6
14
8
3
456
Tue
3
3
4
7
8
9
26
8
2
456
Wed
2
3
6
5
8
10
20
8
1
789
Mon
2
3
4
5
5
10
31
20
6
789
Tue
2
3
5
2
5
18
12
4
6
789
Wed
2
3
6
5
4
10
21
4
6

<tbody>
</tbody>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Actually, that might be as complicated as you think it is! :eek:

Here's what I came up with:

ABCDEFGHIJKLMNO
1CodeMonTueWedThurFriSatSunMonTueWedThurFriSatSun
21231:3010:0010:0010:0010:009:0016:0022:0022:0022:0022:0023:0023:3022:00
345610:0010:0010:0010:0010:009:0011:0022:0022:0022:0022:0023:0023:3022:00
478911:0011:003:0011:0011:009:0012:0022:0022:0022:0022:0023:0023:3022:00
5
6
7CodeDay0:301:001:302:002:303:003:304:004:30
8123Mon2.62.62.81.81.723.14.21.7
9123Tue2.33677811107
10123Wed2457871582
11456Mon3459861483
12456Tue3347892682
13456Wed23658102081
14789Mon234551031206
15789Tue23525181246
16789Wed23654102146
17
18
19CodeTotal between times/dayTotal outside of opening times
2012317.3124.5
214560193
2278941163

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet9

Worksheet Formulas
CellFormula
C20=SUMPRODUCT($C$8:$K$16*($A$8:$A$16=$A20))-B20

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
B20{=SUMPRODUCT(($C$8:$K$16)*($A$8:$A$16=$A20)*($C$7:$K$7>=SUBTOTAL(9,OFFSET($B$2,MATCH($A20,$A$2:$A$4,0)-1,MATCH($B$8:$B$16,$B$1:$H$1,0)-1)))*($C$7:$K$7<=SUBTOTAL(9,OFFSET($I$2,MATCH($A20,$A$2:$A$4,0)-1,MATCH($B$8:$B$16,$I$1:$O$1,0)-1))))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



Change your references to match your workbook. You can see that I've changed a few times for testing. Let me know how this works.
 
Upvote 0
Thank you Eric,

I'm not getting an error with the above but I am getting 0's for everything. I have adapted to my Spread sheet as per the below:

{=SUMPRODUCT(('Profile data'!$G$2:$BB$22815)*('Profile data'!$B$2:$B$22815=Summary!$A2)*('Profile data'!$G$1:$BB$1>=SUBTOTAL(9,OFFSET('NEW 12-12-16'!$C$3,MATCH(Summary!$A2,'NEW 12-12-16'!$A$3:$A$1745,0)-1,MATCH('Profile data'!$F$2:$F$22815,'NEW 12-12-16'!$C$2:$I$2,0)-1)))*('Profile data'!$G$1:$BB$1<=SUBTOTAL(9,OFFSET('NEW 12-12-16'!$J$3,MATCH(Summary!$A2,'NEW 12-12-16'!$A$3:$A$1745,0)-1,MATCH('Profile data'!$F$2:$F$22815,'NEW 12-12-16'!$J$2:$P$2,0)-1))))}

I'm wondering if it's because the cell referencing the Monday opening time (I2 in your data) is locked? However, this should still work and bring data back for one day. I will keep trying because I don't think it's too far off at all but all are returning "0" at present.

Thank you!
 
Upvote 0
I haven't tested your version yet, but it appears to be a match for mine, with the ranges adapted. The locked cell shouldn't matter. Are you entering the formula as an array formula? By which I mean you are entering it using Control+Shift+Enter, and not just manually entering the {} ?
 
Upvote 0
Hi Eric, Yes, I am putting it as an array formula. If the start time is locked, will it take into account different opening times for other properties or all follow the same opening/closing times? I believe it was like for like so can't understand the "0" result but I'll try again later to make sure it is the same. Were you getting the correct results on your example?

Thanks again
 
Upvote 0
The formula should take into account different starting times for each property, regardless of whether the start time is locked. Yes, I did get correct results on my example. I've tried rebuilding your formula, splitting the parts among 3 sheets like you did, but I'm having trouble lining things up. Could you post what the first dozen lines or so from each sheet look like?
 
Upvote 0
Thank you Eric,

Sorry it's been a while but I had a look and it wasn't working because the time formats were not the same. After making sure they were the same format the formula worked fine. Thank you for your help!
 
Upvote 0

Forum statistics

Threads
1,215,990
Messages
6,128,155
Members
449,427
Latest member
jahaynes

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