Calculate max sum of N values in a column

Resod2

New Member
Joined
Aug 3, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi, I am trying to calculate the maximum sum of values within an hour in column. Because the number of values within an hour isn't constant (see my example below) I'm having a lot of trouble trying to get this to work.

As you can see in the sheet below, the times are in column A and the value associated with that time is in column B. In the example below it should output 26% as this is the maximum hour worth of values.

Also, I need it to be a formula father than any VBA. Anyone know how to solve this problem?

Thanks in advance!

Test.xlsx
ABCDE
1TimeValueMax Hour 26
205:452
305:453
407:454
510:452
610:458.7
711:006.2
811:152.1
911:457
1013:152.1
1116:302.1
1216:302
1316:452
Sheet1
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Welcome to the MrExcel forum!

Try:

Excel Formula:
=MAX(SUMIFS(B2:B13,A2:A13,">="&A2:A13,A2:A13,"<="&A2:A13+1/24))
 
Upvote 0
Solution
Welcome to the MrExcel forum!

Try:

Excel Formula:
=MAX(SUMIFS(B2:B13,A2:A13,">="&A2:A13,A2:A13,"<="&A2:A13+1/24))
Thanks Eric, that works perfectly! Could you please explain what the formula is doing, I think I understand but am not sure about some of it i.e. why divide by 24?
 
Upvote 0
Another way:

Book3
ABCDE
1TimeValueMax Hour 26
25:45:00 AM2
35:45:00 AM3
47:45:00 AM4
510:45:00 AM2
610:45:00 AM8.7
711:00:00 AM6.2
811:15:00 AM2.1
911:45:00 AM7
101:15:00 PM2.1
114:30:00 PM2.1
124:30:00 PM2
134:45:00 PM2
Sheet3
Cell Formulas
RangeFormula
E1E1=MAX(MMULT(--(ABS(TRANSPOSE(A2:A13)-A2:A13)<=0.04),B2:B13))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Thanks Eric, that works perfectly! Could you please explain what the formula is doing, I think I understand but am not sure about some of it i.e. why divide by 24?
Sure, in Excel a day is considered to be "1", and fractions of "1" are fractions of a day. So if "1" is one day, then 1/2 = half a day = 12 hours. So 1/24 is 1/24th of a day, or 1 hour. If you were to format your A column as General instead of a time format, you'd see a bunch of decimals.

Let's say you wanted to add up all the values where the time is between 10:00 am and 1:00 pm. The SUMIFS would look like:

Excel Formula:
=SUMIFS(B2:B13,A2:A13,">="&10/24,A2:A13,"<="&13/24)

If you wanted to add up all the values in column B where the time in column A is between the time in A2 and an hour later, it would be:

Excel Formula:
=SUMIFS(B2:B13,A2:A13,">="&A2,A2:A13,"<="&A2+1/24)

If you want to calculate the same thing for EVERY time in column A, it becomes:

Rich (BB code):
=SUMIFS(B2:B13,A2:A13,">="&A2:A13,A2:A13,"<="&A2:A13+1/24)

Excel calculates the SUMIFS for every case, and keeps all the results in an internal array. Then the MAX function gets the maximum value.

Hope this helps! :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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