how to find and sum together all the variables in a table as they relate to daylight hours and night hours

MAP77

Board Regular
Joined
Sep 19, 2018
Messages
60
Office Version
  1. 365
Platform
  1. Windows
I have a csv file of consumption data recorded every 30 mins for 365 days. How would I write a formula to find all the variables that fall between say 6am and 6pm (daylight hours) and 6.30pm to 5.30am (night time hours)? Ideally I would like a total of consumption during daylight hours and night time hours for each month of the year. The file contains a column for the date, time and consumption recorded per 30 mins. I have only limited experience with basic formulas in excel so please speak english. :):eek:
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I have little experience with time values so it took me a while, but here you go:
Code:
=SUMPRODUCT(IF(TIMEVALUE("18:00:00")>B2:B9,IF(B2:B9>TIMEVALUE("6:00:00"),1,0),0)*C2:C9)

Make sure you edit the references and time ranges to your preferences. Furthermore, since this is an array function use ctrl shift enter instead of enter when using the formula.

This formula is derived from the thread in this link: https://superuser.com/questions/297984/how-can-i-sum-values-within-a-specific-time-and-date-range
In English:
The formula first checks if the times in your times column are before a certain time, in this case 6PM. If this is not the case, the IF statement returns "0". If this IS the case, the IF statement checks if the times are after a certain time, in this case 6AM. If this is the case, "1" is returned and otherwise "0". Finally, these 1s and 0s are multiplied by the cells in your consumption column by the SUMPRODUCT statement and these values are then summed.
 
Upvote 0
You could use a sumifs:

=SUMIFS(C:C,A:A,">="&DATE(2018,1,1),A:A,"<"&EDATE(DATE(2018,1,1),1),B:B,">="&TIME(6,0,0),B:B,"<="&TIME(18,0,0))

where the the date is in A, the time in B and consumption is in C. This would calc for January 2018.
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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