How to combine if left and/or functions - excel

I have an example dataset as above. I have 2 columns, namely the duration column and the category column. What is the formula if I want the category column to contain "YES" for duration < 4 hours and "NO" for duration > 4 hours?

B2 Because the conditions <4 hours, so minute no take.
=IF(SUM(TRIM(MID(0&A2,FIND({"d","h"},0&A2)-3,2))*{24,1})<4,"NO","YES")

The following formula should do it, even if you do not have Office 365:
=IF(VALUE(LEFT(A2,FIND(" ",A2)-1)*24)+VALUE(MID(A2,FIND(", ",A2)+2,FIND(" hours",A2)-FIND(", ",A2)-2))<=4,"YES","NO")
It extracts the days value, turns it into a number and multiplies it with 24 (hours).
Next, it extracts the hours value, turns it into a number and adds it to the days result. Finally, everthing is wrapped into an IF statement.
Notes:
The formula can be made more robust, if you substitute the constants (+2) and (-2) by LEN(", ").
For Office 365 there are easier solutions available.

Related

Excel shows name twice

I got a problem with my Excel, where it shows a same name twice, if the 'racers' have the excact same time. For example in the picture the racers 7 & 9 and racers 5 & 10 have the same time, but in the Start grid it shows the same name twice. It should be 4. Racer7 5. Racer9 & 9. Racer5 10. Racer10
The Function of Cell I3 =IF(OR(ISBLANK(B3);ISBLANK(C3));"";INDEX($B$3:$B$32;MATCH(J3;$D$3:$D$32;0))) (I have to use format ';' instead of ',') Function of cell J3 =IFERROR(SMALL($D$3:$D$32;H3);"")
Link to the file (does not work in Google Sheets & the functions have to use local formatting)
xlsx file
MATCH and RANK Getting Sick When Handling Time
Formulas
COMMA
[D3] =IF(NOT(ISNUMBER(C3)),"",ROUND($D$1-A3*"00:10,0"-C3,8))
[H3] =IF(ISNUMBER(K3),RANK(J3,D$3:D$32,2),"")
[I3] =IF(IFERROR(INDEX($B$3:$B$32,SMALL(IF($D$3:$D$32=J3,ROW($J$3:$J$32)-ROW(J$3)+1),COUNTIF($J$3:$J3,J3))),"")=0,"",IFERROR(INDEX($B$3:$B$32,SMALL(IF($D$3:$D$32=J3,ROW($J$3:$J$32)-ROW(J$3)+1),COUNTIF($J$3:$J3,J3))),""))
[J3] =IFERROR(SMALL($D$3:$D$32,A3),"")
[K3] =IFERROR(J3-J$3,IF(I3="","","disqualified"))
COLON
[D3] =IF(NOT(ISNUMBER(C3));"";ROUND($D$1-A3*"00:10;0"-C3;8))
[H3] =IF(ISNUMBER(K3);RANK(J3;D$3:D$32;2);"")
[I3] =IF(IFERROR(INDEX($B$3:$B$32;SMALL(IF($D$3:$D$32=J3;ROW($J$3:$J$32)-ROW(J$3)+1);COUNTIF($J$3:$J3;J3)));"")=0;"";IFERROR(INDEX($B$3:$B$32;SMALL(IF($D$3:$D$32=J3;ROW($J$3:$J$32)-ROW(J$3)+1);COUNTIF($J$3:$J3;J3)));""))
[J3] =IFERROR(SMALL($D$3:$D$32;A3);"")
[K3] =IFERROR(J3-J$3;IF(I3="";"";"disqualified"))
Why is MATCH 'miscalculating' to '7' instead of '6' in cells 'I6' and 'I7' in OP's worksheet (formula in 'D3')?
Time has a ton of decimals so I guess it's 'seeing' the values in 'D8' and 'D9' as different values. To avoid this you can round the values. If you want to use only these values it is enough to round them to 8 decimals for the numbers to be recognized as different even by a millisecond. If you want to sum them there might be some inaccuracies. In OP's case 8 decimals is more than enough.
RANK (formula in 'H3') is also 'miscalculating' if no rounding.
Why the long formula?
Best try it with and without the IF statement and see for yourself.
Here's a Hint:
For this you need a tie breaker. The unfortunately best way of doing this is using a helper column. In my test sheet I used column E but the column could, of course, be anywhere. More importantly, it could be hidden. In this column you enter a formula like
=D3+ROW()/10^8
The point is that the addition must be so small that it makes no difference to the result on rounding. So, the number of results you treat in this may makes a difference. If you find that the addition changes the result in the last row, increase the exponent. The change I made add 0.0001 seconds to each result, multiplied by the row number: 0.0001 in the first row, 0.0002 in the second, 0.0003 in the third etc. Check the results in the 10th and 100th row.
Now the results in column E are all different and it's these results that are used in columns J and I.
[J3] =SMALL($E$3:$E$32,H3)
and
[I3] =INDEX($B$3:$B$32,MATCH(J3,$E$3:$E$32,0))
There will be no more duplicates but the "winner" of a draw is decided by his position in the list.
A solution in old school array-formula-style would be:
Note It's an array-formula which needs to be confirmed through CTRLSHIFTENTER
=IF(OR(ISBLANK(B3),ISBLANK(C3)),"",INDEX($B$1:$B$32,SMALL(IF($D$1:$D$12=J3,ROW($J$1:$J$12)),COUNTIF($J$1:$J3,J3))))
The IF checks the timelist for the current time value and gives all matching lines back which are getting ranked by small. COUNTIF counts the occurences of the current time up to the current line.

COUNTIF function to count specific, but non consecutive, cells in a row

I have an NFL spreadsheet where each row represents a specific team, and every 5 columns represents weekly information about the team (Column A is the team, Columns B-F are stats for week 1, G-K are stats for week 2, etc.). I am trying to perform different calculations on information from the same stat for each week (I.E. sum of columns B,G...). One column includes the teams margin of victory for each week. In order to calculate the teams Win/Loss record, I attempted to use a COUNTIF() function, counting each Margin of Victory column for each week - count a Win for each week where the MOV is greater than 0, Loss for less than zero.
=COUNTIF((Weeks!E3,Weeks!J3,Weeks!O3,Weeks!T3,Weeks!Y3,Weeks!AD3,Weeks!AI3,Weeks!AN3,Weeks!AS3,Weeks!AX3,Weeks!BC3,Weeks!BH3,Weeks!BM3,Weeks!BR3,Weeks!BW3,Weeks!CB3,Weeks!CG3),>0)
The result is a formula parse error, because I've entered too many arguments for the COUNTIF() function (although my assumption was adding parentheses around the data would make it one argument). The desired outcome, reference the picture for example, would be on another sheet to produce 1 loss and 1 tie (in separate cells) for Arizona (Week 1 margin = 0, week 2 margin = -6), and then replicate this over the course of 17 weeks as implemented in the formula.
Maybe some of these formula's:
For positive results:
=SUMPRODUCT((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3>0))
Or:
=SUM(INDEX((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3>0),))
For draws:
=SUMPRODUCT((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3=0))
Or:
=SUM(INDEX((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3=0),))
For negative results:
=SUMPRODUCT((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3<0))
Or:
=SUM(INDEX((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3<0),))
Change A3:CG3 to whichever range it actually goes to.
Instead of making a large countif, you can sum all of the individual countif functions.
=SUM(COUNTIF(Weeks!E3,">0"),COUNTIF(Weeks!J3,">0")...
So on and so forth. Since each countif function will return either a 0 or 1, summing all of those together should hopefully work. It might be a little annoying but this is how I've made formulas like that work. Let me know if this works for you.

Using an average of 10 rows for multiple cells, then moving to the average to the next 10 cells

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))

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

SUM data according to dates in Excel

My problem is the following...
I have a little aeroplane and I need to track the hours. I have to track the hours by sectors and not the total of the day (that's why sometimes I have 2 or 3 on the same day).
Now this is the problem... On column C I need to SUM the hours of the last 7 days. And any given 7 days, not just last week. To do it manually is quite easy... the problem is that I need a formula as my records are quite large...
Here with a small example (let's say that there was NO HOURS before 15/01/2009)...
COLUMN A-------COLUMN B-------COLUMN C
DATE--------------HOURS-------HOURS LAST 7 DAYS
15/01/2009-------01:00-------01:00
15/01/2009-------02:15-------03:15
16/01/2009-------01:15-------04:30
17/01/2009-------01:30-------06:00
18/01/2009-------01:30-------07:30
18/01/2009-------01:00-------08:30
18/01/2009-------02:00-------10:30
19/01/2009-------02:30-------13:00
19/01/2009-------03:00-------16:00
20/01/2009-------////////--------16:00
21/01/2009-------01:00-------17:00
22/01/2009-------01:30-------15:15
23/01/2009-------02:00-------16:00
I've been fighting for the last weeks trying to figure out a formula but no luck... any suggestions?
Thanks
Another solution that basically does much the same as the earlier offered solutions:
In C1, enter the following formula:
{=SUM(IF(($A$1:$A1>=($A1-6))*($A$1:$A1<=$A1), $B$1:$B1, 0))}
And then just drag the formula down.
If you're not familiar with array formulas, the {} outer brackets just indicate that the formula is an array formula. To get it to execute correctly, you need to copy the part inside the {} brackets into the formula bar, and then hit Ctrl+Shift+Enter to indicate that it's an array formula.
First thing is to get the begin date, which would be the following function:
=Now() - 7
If you renamed that cell to "WeekBegin", then you could use the following formula to calculate the total hours:
=SUMIF(A:A,">=" & WeekBegin,B:B)
Notice that I used column references; this was to both simplify the formula, but also allow you to add new data to the end of the range easily. You will need to take care that your WeekBegin cell is not in that column A or column B, otherwise you'll get a circular reference warning.
If you planned to have numeric data above or below your input range, you would need to explicitly call out the sum and criteria ranges as follows:
=SUMIF(A2:A14,">=" & WeekBegin,B2:B14)
Additionally, you may find that your result comes up initially as a decimal. That's Excel's date serial format, so you may need to format your result as time.
Hope that helps!
[Edit: On second pass, if you're looking to sum a range based on a from and to date (so any 7 days as you seem to imply in your post), look for the previous poster's note, i.e.:
=SUM(B:B) - SUMIF(A:A, "<="& BeginDate, B:B) - SUMIF(A:A, ">"& EndDate, B:B)
A more elegant solution is offered in Excel 2007 using the SumIFS() function:
=SUMIFS(B:B, A:A, ">=" & FromDate,A:A, "<" & ToDate)
Note that the arguments for SUMIFS are in a different order than the standard SUMIF.
Happy Summing!]
Here's the data in better format if someone wants to try:
15-Jan-2009 01:00
15-Jan-2009 02:15
16-Jan-2009 01:15
17-Jan-2009 01:30
18-Jan-2009 01:30
18-Jan-2009 01:10
18-Jan-2009 02:00
19-Jan-2009 02:30
19-Jan-2009 03:00
20-Jan-2009
21-Jan-2009 01:00
22-Jan-2009 01:30
23-Jan-2009 02:00
I got the function:
=SUM($B$1:$B$13)-SUMIF($A$1:$A$13, "<="& (A1- 7), $B$1:$B$13) - SUMIF($A$1:$A$13, ">"& (A1), $B$1:$B$13)
This was based on Sum of named ranges conditional to date?.
The idea is to first compute the total sum: SUM($B$1:$B$13)
then subtract any values that happened older than 7 days ago: SUMIF($A$1:$A$13, "<="& (A1- 7), $B$1:$B$13)
then subtract any values that happened in the future: SUMIF($A$1:$A$13, ">"& (A1), $B$1:$B$13)
The point is to use SUMIF function, which "adds the cells specified by a given criteria."

Resources