SUMIFS Between Two Dates and Times in Excel - excel

I am trying to get the summation of a column between two dates and two times, where the days are different.
The columns I have are:
Table 1 = Time1, Time2, Date1, Date2
Table 2 = Date, Time, Event
Ideally, this formula would give the total number of events between Date1/Time1 and Date2/Time2
I have tried the formula below, but am receiving the total number of events between those two times on both dates, instead of the number of events between the two.
Time Start Time End Date Start Date End
23:54:00 0:04:00 9/27/2021 9/28/2021
=SUMIFS(Sheet1!$G:$G,Sheet1!$D:$D,">="&'ProductMadness-Postlogs Export'!U84,Sheet1!$D:$D,"<="&'ProductMadness-Postlogs Export'!V84,,Sheet1!$C:$C,">="&'ProductMadness-Postlogs Export'!Y84,Sheet1!$C:$C,"<="&'ProductMadness-Postlogs Export'!Z84)
*For context, Sheet1 has the event data, "ProductMadness - Postlogs" has the date and time data

If I understand this correctly the following formula should be what you are looking for.
=SUMIFS(Sheet1!$G:$G,Sheet1!$D:$D,">"&'ProductMadness-Postlogs Export'!U84,Sheet1!$D:$D,"<"&'ProductMadness-Postlogs Export'!V84,Sheet1!$C:$C,">"&'ProductMadness-Postlogs Export'!Y84,Sheet1!$C:$C,"<"&'ProductMadness-Postlogs Export'!Z84)
By excluding the equal to it only counts what is between. That being said this still may not do what you want depending on if the times are just time values. For example, 23:54:00 is greater than 0:04:00. Since you were receiving results in the past, I am assuming your time have the full date value and are just formatted as time.

Related

How to filter out partial match in an Excel row?

I have an Excel sheet with dates in the rows. A given month should be used only once in a row. How can I filter out, if there are two dates in the same row from the same month?
For example I have the following array, and I would like to have as a result, that there is a match in this row (2012-03).
2012-03-04 2012-02-05 2012-04-06 2012-03-07 2012-10-08 2012-11-09 2012-12-10
I have tried to combine aggregate and match functions, but I cannot find out how to do it properly.
One of my codes, of course it gave an error:
=aggregate(9,6,(MATCH("*"&LEFT(A8,7)&"*","*"&LEFT(b8,7)&"*",0), MATCH("*"&LEFT(b8,7)&"*","*"&LEFT(c8,7)&"*",0)))
Ok, now I have tried another way, and I could get a solution, but with a code which is like a km long...I have first created a new dataset, cutting down the days by using: =""&LEFT(A8,7)&""
Then I have compared all the cells in a given row of my new dataset. Could someone help me how to shorten the exact( ) parts? The aim is to compare all.
=if((or(exact(A2, B2), exact(A2,C2),exact(A2,D2),exact(A2,E2),exact(A2,F2),exact(A2,G2),exact(A2,H2),exact(A2,I2),exact(A2,J2),exact(A2,K2),exact(A2,L2),exact(A2,M2),exact(A2,N2),exact(A2,O2),exact(A2,P2),exact(A2,Q2),exact(A2,R2),exact(B2,C2),exact(B2,D2),exact(B2,E2),exact(B2,F2),exact(B2,G2),exact(B2,H2),exact(B2,I2),exact(B2,J2),exact(B2,K2),exact(B2,L2),exact(B2,M2),exact(B2,N2),exact(B2,O2),exact(B2,P2),exact(B2,Q2),exact(B2,R2),exact(C2,D2),exact(C2,E2),exact(C2,F2),exact(C2,G2),exact(C2,H2),exact(C2,I2),exact(C2,J2),exact(C2,K2),exact(C2,K2),exact(C2,L2),exact(C2,M2),exact(C2,N2),exact(C2,O2),exact(C2,P2),exact(C2,Q2),exact(C2,R2),exact(D2,E2),exact(D2,F2),exact(D2,G2),exact(D2,H2),exact(D2,I2),exact(D2,J2),exact(D2,K2),exact(D2,L2),exact(D2,M2),exact(D2,N2),exact(D2,O2),exact(D2,P2),exact(D2,Q2),exact(D2,R2),exact(E2,F2),exact(E2,G2),exact(E2,H2),exact(E2,I2),exact(E2,J2),exact(E2,K2),exact(E2,L2),exact(E2,M2),exact(E2,N2),exact(E2,O2),exact(E2,P2),exact(E2,Q2),exact(E2,R2),exact(F2,G2),exact(F2,H2),exact(F2,I2),exact(F2,J2),exact(F2,K2),exact(F2,L2),exact(F2,M2),exact(F2,N2),exact(F2,O2),exact(F2,P2),exact(F2,Q2),exact(F2,R2),exact(G2,H2),exact(G2,I2),exact(G2,J2),exact(G2,K2),exact(G2,L2),exact(G2,M2),exact(G2,N2),exact(G2,O2),exact(G2,P2),exact(G2,Q2),exact(G2,R2),exact(H2,I2),exact(H2,J2),exact(H2,K2),exact(H2,L2),exact(H2,M2),exact(H2,N2),exact(H2,O2),exact(H2,P2),exact(H2,Q2),exact(H2,R2),exact(I2,J2),exact(I2,K2),exact(I2,L2),exact(I2,M2),exact(I2,N2),exact(I2,O2),exact(I2,P2),exact(I2,Q2),exact(I2,R2),exact(J2,K2),exact(J2,L2),exact(J2,M2),exact(J2,N2),exact(J2,O2),exact(J2,P2),exact(J2,Q2),exact(J2,R2),exact(K2,L2),exact(K2,M2),exact(K2,N2),exact(K2,O2),exact(K2,P2),exact(K2,Q2),exact(K2,R2),exact(L2,M2),exact(L2,N2),exact(L2,O2),exact(L2,P2),exact(L2,Q2),exact(L2,R2),exact(M2,N2),exact(M2,O2),exact(M2,P2),exact(M2,Q2),exact(M2,R2),exact(N2,O2),exact(N2,P2),exact(N2,Q2),exact(N2,R2),exact(O2,P2),exact(O2,Q2),exact(O2,R2),exact(P2,Q2),exact(P2,R2),exact(Q2,R2))),"same month","ok")
Thank you in advance.
I am not sure if there is a better way, but this is how I'd tackle the problem based on my Excel knowledge:
Add data of dates above in cells A1-G1
On row below date add formulas for dates: A2=DATE(A1) ..... G2=DATE(G1)
At the end of the original row of dates add the numbers 1 thru 12:
using formula cell H1=1, I1=H1+1 ..... S1=R1+1
After the months on row 2:H2=COUNTIF($A2:$G2,H1) ..... S2=COUNTIF($A2:$G2,S1)Counting frequency for each of the 12 months
T2=MAX(H2:S2)
Then select on cell T2being more than 1.
Here it is as a Google sheet (you can download it and open in Excel if you want)
Maybe this will help. Assume that the range of dates is in $A$1:$G$1. Also assume that the entries are numerical dates; if they are instead text you can handle this by using the DATEVALUE function. Then we can get the years and months of the range with:
{=YEAR($A$1:$G$1)}
{=MONTH($A$1:$G$1))
This and all other formulas must be entered as array formulas (CrtlShiftEnter).
We next convert back to a date, but use 1 for the day, so that all dates get shifted to the first day of the month (this means that any dates from the same month are shifted to the same date):
{=DATE(YEARS,MONTHS,1)}
We can produce an NxN comparison of the shifted dates by:
{=TRANSPOSE(SHIFTED_DATES)=SHIFTED_DATES}
We can count the number of True's in this array by:
{=SUM(--(ARRAY))}
If there we no dates from the same month we'd expect this to sum to N because this method compare each date to itself as well as the other dates. The causes the N elements on the main diagonal of this array to be True. If any dates are in the same month off-diagonal elements will also be True. So to detect if there are dates from the same month we make the comparison:
{=SUM(--(ARRAY)) > N}
or more generally:
{=SUM(--(ARRAY)) > COUNT($A$1:$G$1)}
Rolling all of these up into one formula:
=IF(SUM(--(TRANSPOSE(DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1))=DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1)))>COUNT(DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1)),"same month","ok")
If your dates are in a range other than $A$1:$G$1 then make the appropriate substitutions.
Hope that helps.

Count IF with Date and Time in single Cell (EXCEL)

I have a spreadsheet that lists the date and time of an event in the same cell (mm/dd/yy h:mm). I need to find a way to count how many events took place between a certain time range in a Hourly Basis.
I could sum if the cell contains dates only however the cell contains with date which i am unable to get the values.
Basically, all datas are in cell A, so i need to count how many events happened at 6am, 7am , and so on... as on hourly basis.
Your column A looks like properly formatted date & time value, so its manipulation is easy. If it's not (ie, not date but text) you should first convert it to date value.
=DATE(MID(A2,7,4), MID(A2,4,2), LEFT(A2,2)) + TIME(MID(A2,12,2), MID(A2,15,2), RIGHT(A2,2))
Say this was C2. Now that column C is date & time, set $D$2 to date to query(ex 2017-03-26), E2 to start time(ex 6:00), and F2 to end time(ex 7:00), then you can count events from 6:00 to 7:00 like this:
=COUNTIFS(C:C,">="&($D$2+E2), C:C,"<"&($D$2+F2))
Sample file is here and its screenshot is below.
If the times spanned different dates and you still wanted to see how many events happened in a particular hour of the day, you would need an array-type formula, e.g. if the start time in hours (entered as a normal number) is in C2
=SUMPRODUCT(--(HOUR($A$2:$A$10)=C2))
or if the start hour is entered as a time
=SUMPRODUCT(--(HOUR($A$2:$A$10)=HOUR(C2)))

average with multiple conditions on excel

I generally ask Python or VBA questions, but this has been annoying me for the past 4.5 hours and i need it to finish a macros and i'm just getting div/0 error.
In excel i have five columns:
1. Date when the item entered the queue (A)
2. time when the item entered the queue (B)
3. Date when the item left the queue (C)
4. time when the item left the queue (D)
5. time the item was in the queue (E)
I need the average of time of the items that entered and left the queue between 16:00 yesterday and 16:00 today. Also for it to ignore numbers < than 1 (because if an item has been there for over 24 hours the default value is negative).
I tried tried this and no results :(
=AVERAGEIFS(E1:E4,A1:A4,"=today()-1",B1:B4,">16:00",C1:C4,"=today()",D1:D4,"<16:00")
Any ideas would be appreciated! Thanks in advance :)
Your formula is saying this:
=AVERAGEIFS(E1:E4,A1:A4,"=today()-1",B1:B4,">16:00",C1:C4,"=today()",D1:D4,"<16:00")
Take the average of E1:E4 if...
A1:A4 are equivalent to the string "=today()-1"
B1:B4 are equivalent to the string ">16:00"
C1:C4 are equivalent to the string "=today()"
D1:D4 are equivalent to the string ">16:00"
What you want it to say is:
Take the average of E1:E4 if...
A1:A4 are equivalent to the result of the formula =today()-1
B1:B4 are less than 16 hours
C1:C4 are equivalent to the result of the formula =today()
D1:D4 are less than 16 hours
Let's tackle 2 and 4 first.
In Excel, 1 day (24 hours) = 1. Times are stored as decimal values as a percentage of a day:
1 day = 1
1 day = 24 hours
1 hour = 1 / 24
16 hours = 16/24 = 2/3
So instead of B1:B4,">16:00" you should rewrite the formula as:
B1:B4,">"&2/3
The & concatenates the greater than sign, and 2/3 will give the decimal value equivalent to 16:00. In the end you will get a string equal to ">.6666666666"
(You can also just use B1:B4,">.6666666666666" if you'd like)
For items 1 and 3, you don't need to use quotes at all. So instead of A1:A4,"=today()-1" you can just use the following:
A1:A4,today()-1
C1:C4,today()
Putting this all together, the following formula should work:
=AVERAGEIFS(E1:E4,A1:A4,today()-1,B1:B4,">"&2/3,C1:C4,today(),D1:D4,"<"&2/3)
If you are looking for "items that entered and left the queue between 16:00 yesterday and 16:00 today" isn't it possible that some of those entered the queue today (or left the queue yesterday)? If so you would need to check for items that entered today as well, surely? To do that is difficult with AVERAGEIFS function - it might be easier to use an "array formula" like this:
=AVERAGE(IF(A1:A4+B1:B4>=TODAY()-1/3,IF(C1:C4+D1:D4<TODAY()+2/3,E1:E4)))
confirmed with CTRL+SHIFT+ENTER
I'm assuming that the formula doesn't have to explicitly deal with your negative values because those will only occur for items which have been there for more than 24 hours and the IF functions will exclude those anyway...
If you want to do the same with AVERAGEIFS you'd need to create two additional columns with the entry/exit dates/times added, e.g. if column G is the sum of columns A and B and column H is the sum of columns C and D you could use this version
=AVERAGEIFS(E1:E4,G1:G4,">="&TODAY()-1/3,H1:H4,"<"&TODAY()+2/3)
Note that I used >= and < deliberately to avoid double-counting/non-counting across several days

Wrong results appearing for date formula

I'm using the formula =NETWORKDAYS(start_date,end_date) to calculate the number of working days between an estimated delivery date and the actual delivery date of products.
It is working fine to some extent, however if there is a recorded delivery date but no estimated date, it provides a value of 29,600+. Similarly if there is an estimated date but no delivery date (ie the item hasn't yet been received) it returns a value of -29,600+.
What addition to this formula can I add to stop this happening?
Also, if the delivery date and estimated delivery date are the same, it returns a value of 1, when it should be 0?
Here's ideally what I want:
the two columns with dates in are E and M, and I want the following to happen:
When E is blank but N isn't, the value 'no est' will appear
When N is blank but E isn't, the value 'no del' will appear
When both E and N are blank, the value 'no data' will appear
When neither are blank, i want it to use the formula =NETWORKDAYS($E,$N) to calculate the amount of days between the two dates
This is the formula I have created, but excel won't accept it
=IF(E21=ISBLANK,(=IF(N21=ISBLANK,"no data","no est")),(=IF(N21=ISBLANK,"no del",(=NETWORKDAYS($E,$N)))))
Thanks
Similar to your attempt:
=IF(AND(ISBLANK(E2),ISBLANK(M2)),"no data",IF(ISBLANK(E2),"no est",IF(ISBLANK(M2),"no del",NETWORKDAYS(E2,M2))))
(probably could be abbreviated slightly, but relatively clear).

formula to minutes and seconds down into total amount in seconds

I am looking a formula for excel that minus a feild called end time by field start time and answer will show as the total amount of seconds the calls lasted.
For example i have call that ended 04:04:35 and started at 03:51:51 and i need to how many seconds that would be in total and instead of working by calucator would like to know if there fourmula to do it
thanks
simon
The easiest is to set the two cells as time (hh:mm:ss) then subtract them.
Put the result on a new cell, formatted as a number and multiply the result by 86400.
See this post for the explanation
EDIT: the final cell has to be in number format, something like this:
A B C
Cells 1 03:51:51 04:04:35 =(B1-A1)*86400
Cell format: hh:mm:ss hh:mm:ss number

Resources