I'm trying to get an Average If function to work, the basis is this.
Sheet 1
TIME Duration (sec)
4/24/2013 5:04 57
4/24/2013 5:09 122
4/25/2013 12:22 341
Sheet 2
Date Average Duration
4/24/2013
4/25/2013
My question I have right now is what should the function for average duration be?
I have something like this:
=AVERAGEIF('Sheet1'!C:C,SEARCH("4/24/2013", 'Sheet1'!C:C))
Column C in sheet 1 is the date, Column D is the duration
This will give you exactly what you are looking for and it will disregard the times so that you can search by an entire day regardless of time. Please remember to press Ctrl+Shift+Enter when putting this equation in as it is an array equation.
=SUM(IF(TEXT(DateSearchRange,"m/dd/yy")=TEXT(DateSearchingCell,"m/dd/yy"),DurationRange,0))/SUM(IF(TEXT(DateSearchRange,"m/dd/yy")=TEXT(DateSearchingCell,"m/dd/yy"),1,0))
If you are prepared to insert a helper column, between the present C and D, with =LEFT(C2,5) copied down (assuming 57 is in Row2 and Date is in ColumnA) the formula you tried should work as adapted:
=AVERAGEIF(Sheet1!D:D,A2,Sheet1!E:E)
=SEARCH is not suitable for the condition because it returns the position of one string within another and the second C:C pair would be trying to average TIME, rather than Duration.
Related
I have a large column of data where every 10 rows is a different set.
What I would like to do is get the average of those 10 rows, and then subtract that from every individual measured value.
Then it moves to the next 10, takes the average of those, and subtracts it from the 10 data points that yielded the new average.
I've tried using MOD and plenty of formulas and dragging out some kind of formula but Excel's pattern recognition is not working at all in this case.
Example of what I'm trying to do using 3 values instead of 10
The output I want takes the average of the first 3 values ((1+2+3)/3=2), then subtracts it from those 3 values and outputs it as the result. (1-2=-1, 2-2=0, 3-2=1). Then it repeats the same thing with the next 3 and the results from the previous 3 do not affect it.
Values________Average_______Result
1|__________________________-1
2|______________2 __________ 0
3|__________________________1
2|__________________________-2
5|______________4 __________ 1
5|___________________________1
2|___________________________-1
5|_____________3_____________2
2|___________________________-1
(I'm so sorry about the awful table)
Any help would be greatly appreciated! Thank you.
Using your data and doing every three:
=A2-AVERAGE(INDEX(A:A,INT((ROW(1:1)-1)/3)*3+2):INDEX(A:A,INT((ROW(1:1)-1)/3)*3+4))
To change to 10 change the each /3 to /10 and *3 to *10 this is the interval. You will also need to change the +2 to the first row of data and the +4 to +11 or +[the interval]-1
I like Scott's answer better, but since I had worked it out while he was typing, I'll add my solution as well.
I'm using the INDIRECT function to build the range reference and calculating the range for the AVERAGE by using MOD on the ROW function.
Basically you're looking to average over the first ten rows, so you need the range A1:A10, then A11:20, and so on. In order to calculate the beginning row, take your current ROW() and subtract the MOD 10 of its previous row: ROW()-MOD(ROW()-1,10). The last row of the group just adds 9 rows: ROW()-MOD(ROW()-1,10)+9.
Everything in Column B uses the formula:
=AVERAGE(INDIRECT("A"&ROW()-MOD(ROW()-1,10)&":A"&ROW()-MOD(ROW()-1,10)+9))
I try to be as simple as possible.
I have an Excel workbook, with 2 sheets. At the very end, I will need a %, that is divided by 2 specific values.
My problem is, that there is a lot of information in the Excel sheet, and I need to aware of 2 columns at least... let me show:
As you see, my table looks like this. It is a really really long report, because you can see, there is 24 row for 1 specific time (10:00), and it is generated in every 5 minutes, soooo it is long as hell...
column: 10:00 (time)
column: 1 (type)
column: A, B, C, D, T (type 2)
column: not important
column: total amount
As you see, I need to be aware of the time, the type, the type 2.
As I told you, I need a % as the following:
10:00 1 A 1 ***5***
10:00 1 T 1 ***100***
So the result should be 5%, because 5 is the 5% part of the 100. So the divide is in this case: 5/100*100.
BUT the time need be the same (10:00), the type (1) need to be the same. And this 5% need to be copied to another cell. It is critical, that I need to divide the same types.
I hope it was understandable, because I really don't have any idea, how can I handle this. I tried with VBA, but I wasn't able to create a proper formula for this a well.
Can you assist? Thank you
I have a bunch of sequential rows and I'm trying to average the last 90 based on a criteria. The average needs to be in a single cell, rather than a column that calculates a running average. I figured out how to calculate an average for the last 90 rows, but I am not able to correctly add the if function to meet the criteria prior to averaging.
Data:
sale type (b) Data(c) Rownumber (E)
a 45 1
b 35 2
c 36 3
c 56 93
Here is the average function that's working correctly AVERAGE(OFFSET(E2,COUNTA(E:E)-1,-2,-90)).
Here is the AVERAGEIF function that I'm trying to run that is giving incorrect data:
=AVERAGEIF(B:B,I15,OFFSET(E2,COUNTA(E:E)-1,-2,-90))
I15 cell in this case, is the sale type that I am trying to match.
Thanks in advance for the help!
=AVERAGEIF(OFFSET(B2,COUNTA(E:E)-2,0,-90),$I$15,OFFSET(C2,COUNTA(E:E)-2,0,-90))
first: you need to "-2", not "-1" from your row, you're not getting the last 90 with -1 .. (test it by changing a record in data to "999" at the outskirts. You'll see it pick up that value when the AVG changes dramatically.)
second: your and range have to match .. heights anyway. So use the same offset formula in both.
To slightly optimize this, you could calc that "COUNTA(E:E)-2" in another column, name it, then just reference it in both cases (that way Excel only calcs it once, not twice). ;)
Also, if the I15 cell is a single cell, you might want to $I$15 it to be safe. I don't think this matters in this case, just a habit of doing that to single, isolated cells that aren't part of a range :)
If you actually have row numbers (of the data) in column E you could use AVERAGEIFS and just use another criteria based on column E, like this:
=AVERAGEIFS(C:C,B:B,I15,E:E,">"&MAX(E:E)-90)
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
Column A Column B
13-06-2013 10:50
13-06-2013 11:30
13-06-2013 12:40
14-06-2013 10:30
I need to find the values which are before a particular entry date and time.
For example, say I want to find the values in the example table above that are immediately prior to the values "13-06-2013" and "12:30".
Since 12:30 is not in column B, how do I find the values I am looking for? The answer should be 13-06-2013 and 11:30.
C7 =VLOOKUP(A7&B7,A1:C4,3,TRUE)
Here A1 = B1&C1
A B C
1 414380.451388888888889 13-06-2013 10:50
2 414380.479166666666667 13-06-2013 11:30
3 414380.527777777777778 13-06-2013 12:40
4 414390.4375 14-06-2013 10:30
5
6 Enter date Enter Time Returned Time
7 13-06-2013 12:30 11:30:00
Setting 'range_lookup' as 'True' adds the flexibility to return the closest approximate value if the exact value is not available.
I think you're looking for something like this. using index and match.
I didn't take into account the date for now. but this gives you an example.
You can compare date strings with operators like > or < etc. Concatenate your values in columns A & B, compare to the desired date/time string. In cell C1 put the following formula, and then drag down:
="13-06-2013 12:30"<A1&" "&B1
or more specifically, depending on which "12:30" you want (AM or PM), ="13-06-2013 12:30AM" or ="13-06-2013 12:30PM"
Your data in column B may default to AM unless otherwise specified/imported differently, so you may need to tweak the data or to account for this.
Here is another approach to answering your question that uses a combination of MATCH, INDEX, and array operations to provide a compact formula solution that does not rely on helper columns.
I'll assume that your two columns of dates and times are in cells A2:B5, and the two date and time values that you want to look up are in cells A9:A10. Then the following two formulas will return what you require, the latest date and time values in your data that are less than or equal to the date and time that you are looking up. (The dollar signs in the formulas are hard on the eyes, but they are important if you will need to copy the formulas to other locations; for clarity, I omit them in the discussion that follows.)
DATE: =INDEX($A$2:$B$5,MATCH(A9+A10,$A$2:$A$5+$B$2:$B$5,1),1) --> 13-06-2013
TIME: =INDEX($A$2:$B$5,MATCH(A9+A10,$A$2:$A$5+$B$2:$B$5,1),2) --> 11:30 AM
These are array formulas and need to be entered with the Control-Shift-Enter key combination. (Of course, only the bits starting with the equal (=) sign and ending with the last parenthesis need to be entered into the worksheet.)
Things to consider:
The formulas assume that your data are valid Excel date and time values. Excel date values are whole numbers that count the number of days that have elapsed since January 1, 1900; Excel time values are decimal amounts between 0 and 1 that represent the fraction of 24 hours that a particular time represents. While your example data don't display AM or PM, I assume that their underlying values do have that information.
If your values are text (having been imported from another source, for instance), you should convert them to date/time values, if lucky, using only Excel's DATEVALUE and TIMEVALUE functions; if not so lucky, using some combination of Excel's string manipulation functions as well. (The values could be kept as strings, but you would almost certainly need to massage them so they would compare correctly "alphabetically" - much easier just to deal with Excel date/time values.)
If they are not already, your dates and times will need to be sorted from smallest to largest. (Your sample looks like they are sorted, and the formulas assume as much.)
How the formulas work
The basic idea behind the formulas is two-fold: first find the row in your data that holds the latest (largest) date and time that is still less than or equal to the date and time you are looking up. That row information can then be used to fetch the final result from each column of the data range (one for date and one for time).
Since both date and time figure in to what point in time is latest, the date and time components of both the value to be looked up and the values that will be searched must be combined somehow.
This can be achieved by simply adding the dates and times together. This does nothing more than what Excel does: an Excel date/time value has an integer part (the number of days since 1/1/1900) and a decimal part (the fraction of 24 hours that a particular time represents).
What is neat here is that the adding up of the dates and times - and the lookup of the particular date and time - can be done all at once, on the fly.
Take a look at the MATCH: The cells that contain the date and time to be looked up - A9 and A10 - are added together, and then this sum is matched against the sum of the date column (A2:A5) and the time column (B2:B5) - an operation that is possible of Excel's array arithmetic capabilities. The match returns a value of 2, indicating correctly that the date and time that fill your requirements are in row 2 of the data table.
DATE/TIME MATCH: = MATCH( A9+A10, A2:A5 + B2:B5, 1 ) --> 2
The 1 that is the final argument to the MATCH function is an instruction that the match results be calculated to be less than or equal to the value to be looked. It is the default value and is often omitted, or replaced with another value (for example, using a value of 0 will produce an exact match, if there is one).
(For readability, I've removed the dollar signs that are in the full formula; these anchor a range so that it remains the same even if the formula is copied to another location.)
Having figured out the row to look in, the rest of the formula is straightforward. The INDEX function returns the value in a data range that is at the intersection of a specified row and column. So, for the date in question, the formula reduces to:
DATE FETCH: = INDEX( A2:B5, 2, 1) --> 13-06-2013
In other words, INDEX is to return the value in the second row and first column of the data range A2:B5.
The formula for the time proceeds in exactly the same fashion, with the only difference that the value is returned from the second column of the data range.