Using Formula to determine Shift from Time data (Excel) - excel

I have a column of time data formatted like this: Machine_Usage
I want to make an IF statement that returns 1, 2 or 3 corresponding to first, second or third shift if the times fall between certain values.
I already tried many times but not worked, please help me.
I want to find the right formula/syntax that can solved this problem for length of use of the machine based on the shift.

This is a possible approach, but not an answer because the question needs clarification on how to handle the following situations:
The interval [Start, End] is not within a single shift. According to some input data, it starts in one shift and ends in another one.
When End corresponds to a day after Start. This only can apply for shift 3, but based on the data there is no such scenario
In cell F2 put the following formula (the result is spilled, no need to drag down the formula)
=LET(start, C2:C20, end, D2:D20, lkup, H2:J4, shift, INDEX(lkup,,1),
lkStart, INDEX(lkup,,2), lkEnd, INDEX(lkup,,3),
MAP(start, end, LAMBDA(ss,ee, LET(startI, INT(ss) + lkStart,
endI, INT(ss) + lkEnd,
result, FILTER(shift, (ss >= startI) * (ee < endI), "Shift not found"),
IF(ROWS(result) > 1, "Overlap", result)
)))
)
Here is the output:
As you can see based on the data issue mentioned before no shift was found for any of the rows. Probably after data clean-up or more clarification, the formula should return a more realistic result.
Even the Shift information is represented in hh:mm format (see the previous screenshot). The end date of the last shift corresponds to the next day. Therefore the numeric values associated with the hours are the following:
Shift Start End
1 0.25 0.58
2 0.58 0.92
3 0.92 1.25
The logic of the formula is based on the above settings.

Related

How to get start and end time of each shift

I have a timeshift table, where 0 means no activity (or day off) and values > 0 are different activities.
I can find the start hour of the first shift and the end hour of the last shift, but i'm struggling to find the last hour of the first shift and the first hour of the second shift.. The table should look like this:
EXCEL
Taking in account the example above, what i exactly want is a formula to determine that:
On row 3, the end of the first shift is column S (or 14:00) and the beginning of the second shift is column V (or 15:30)
On row 6, the end of the first shift is column U (or 15:00) and the beginning of the second shift is column X (or 16:30), and so on...
Here's a possible approach. Since there aren't too many columns, you could join them all together and use Find to get the transitions from 0 to 1 and 1 to 0:
=LET(join,TEXTJOIN("",,D3:AY3),start1,FIND("01",join)+1,finish1,FIND("10",join,start1),start2,FIND("01",join,finish1)+1,finish2,FIND("10",join,start2),INDEX(D2:AY2,1,HSTACK(start1,finish1,start2,finish2)))
Then you would need to add error handling for the case where the person worked no shifts or only one shift and also allow for the case where a shift started at exactly 6:30 or finished at exactly 6:00.
EDIT
An improved formula could look like this:
=LET(join,TEXTJOIN("",,D3:AZ3)&0,
LC,COLUMNS(D3:AZ3),
start1,IFERROR(FIND("1",join),LC),
finish1,IFERROR(FIND("10",join,start1),LC),
start2,IFERROR(FIND("1",join,finish1+1),LC),
finish2,IFERROR(FIND("10",join,start2),LC),
INDEX(D$2:AZ$2,1,HSTACK(start1,finish1,start2,finish2)))
where AZ2 contains a suitable character string to indicate missing data.

Excel: How to find closest number in table, many times

Excel
Need to find nearest float in a table, for each integer 0..99
https://www.excel-easy.com/examples/closest-match.html explains a great technique for finding the CLOSEST number from an array to a constant cell.
I need to perform this for many values (specifically, find nearest to a vertical list of integers 0..99 from within a list of floats).
Array formulas don't allow the compare-to value (integers) to change as we move down the list of integers, it treats it like a constant location.
I tried Tables, referring to the integers (works) but the formula from the above web site requires an Array operation (F2, control shift Enter), which are not permitted in Tables. Correction: You can enter the formula, control-enter the array function for one cell, copy the formulas, then insert table. Don't change the search cell reference!
Update:
I can still use array operations, but I manually have to copy the desired function into each 100 target cells. No biggie.
Fixed typo in formula. See end of question for details about "perfection".
Example code:
AI4=some integer
AJ4=MATCH(MIN(ABS(Table[float_column]-AI4)), ABS(Table[float_column]-AI4), 0)
repeat for subsequent integers in AI5...AI103
Example data:
0.1 <= matches 0
0.5
0.95 <= matches 1
1.51 <= matches 2
2.89
Consider the case where target=5, and 4.5, 5.5 exist in the list. One gives -0.5 and the other +0.5. Searching for ABS(-.5) will give the first one. Either one is decent, unless your data is non-monotonic.
This still needs a better solution.
Thanks in advance!
I had another problem, which pushed to a better solution.
Specifically, since the Y values for the X that I am interested in can be at varying distances in X, I will interpolate X between the X point before and after. Ie search for less than or equal, also greater than or equal, interpolate the desired X, then interpolate the Y values.
I could go a step further and interpolate N - 1 to N + 1, which will give cleaner results for noisy data.

Excel: Calculate average time (duration), with criteria, between 2 columns

Breaking my head over this, time to look for help :(
I have a sheet with raw data, as illustrated below.
I'd like to calculate the average duration per TestName (column A) between the 2 timestamps (B and C) in another sheet.
How can I do this in 1 formula?
Note 1: The correct answer is (done manually)
test1 = 26:41:23
test2 = 08:23:10
Note 2: 1 formula please, without adding extra columns to calculate the duration per each first
Note 3: I cannot change the format of the raw data
Note 4: ignore empty fields
Thank you!
Use a new Column D to calculate the difference between start and end date on each row:
=DATEVALUE(C2)+TIMEVALUE(C2) - (DATEVALUE(B2)+TIMEVALUE(B2))
Next calculate the average on test1 and test2
=AVERAGEIFS($D:$D, $A:$A, "test1")
=AVERAGEIFS($D:$D, $A:$A, "test2")
Note that I'm using a comma as separator, in some languages, other separators, like semicolon are needed to write the formulas properly.
Now format the view to display at least the days in addition to the time: "DD - hh:mm:ss". Going beyond 31 days is a bit difficult as the month will count up.
If you don't like the formatting, go with the raw number format and extract the information through a bit of math. If it shows for example 1,5 it means one and a half days. I hope you can handle converting decimals to hours, minutes and seconds. MOD(ulo) and Rounddown are going to be your friends. :-)

If statment of a cell calculated using formula

My formula is giving me unexpected responses.
=IF(I5+H5=0,"Paid","Due")
see below
H I J k
-£34.40 £34.40 £0.00 Due
Cell H is calculated with this
=(SUM(F5+G5))*-1
See correct output with exact same formula on same worksheet
=IF(I3+H3=0,"Paid","Due")
H I J K
-£205.44 £205.44 £0.00 Paid
Cell H is calculated he same
=(SUM(F3+G3))*-1
Any ideas why the top calculation not correct but the bottom one is.
This is most likely the floating point issue. You should not compare floating point numbers directly with = because computers can't store the full decimal places. Just like if you divide 1 dollar by 3, you end up with .3333333333333 cents, well if you add 3 of those you don't necessarily get back 1 dollar, but slightly less due to the "lost" 3333's at the end. The proper way to compare is using a Delta threshold, meaning "how close" it needs to be.
so instead of
if (a+b=c,"paid", "due")
you would do
if(ABS(c-(a+b))<.01, "paid", "due")
so in that case .01 is the delta, or "how close" it has to be. It has to be within 1 cent. the formula literally means "if the absolute value of the difference between c and (a+b) is less than 1 cent, return paid, else return due. (of course, this will say due if they overpaid, so keep that in mind)
you should always do this.

How to exclude 0 from MIN formula Excel

i need to know how can i exclude 0 from rows and get the MIN Value.
But also i need to exlude the F1 Cell.
Ex:
A B C D E F
1 0 18 20 0 150 = 18
but if i do this In excel with =MIN(A1,B1,C1,D1,E1) return 0.
Any help is appreciated.
Try this formula
=SMALL((A1,C1,E1),INDEX(FREQUENCY((A1,C1,E1),0),1)+1)
Both SMALL and FREQUENCY functions accept "unions" as arguments, i.e. single cell references separated by commas and enclosed in brackets like (A1,C1,E1).
So the formula uses FREQUENCY and INDEX to find the number of zeroes in a range and if you add 1 to that you get the k value such that the kth smallest is always the minimum value excluding zero.
I'm assuming you don't have negative numbers.....
Enter the following into the result cell and then press Ctrl & Shift while pushing ENTER:
=MIN(If(A1:E1>0,A1:E1))
Not entirely sure what you want here, but if you want to discount blank cells in the range and pass over zeros then this would do it; if a little contrived:
=MIN(IF(A1:E1=0,MAX(A1:E1),A1:E1))
With Ctrl+Shift+Enter as an array.
What I'm doing here is replacing zeros with the maximum value in the list.
if all your value are positive, you can do -max(-n)
Solutions listed did not exactly work for me. The closest was Chief Wiggum - I wanted to add a comment on his answer but lack the reputation to do so. So I post as separate answer:
=MIN(IF(A1:E1>0;A1:E1))
Then instead of pressing ENTER, press CTRL+SHIFT+ENTER and watch Excel add { and } to respectively the beginning and the end of the formula (to activate the formula on array).
The comma "," and "If" statement as proposed by Chief Wiggum did not work on Excel Home and Student 2013. Need a semicolon ";" as well as full cap "IF" did the trick. Small syntax difference but took me 1.5 hour to figure out why I was getting an error and #VALUE.
Throwing my hat in the ring:
1) First we execute the NOT function on a set of integers,
evaluating non-zeros to 0 and zeros to 1
2) Then we search for the MAX in our original set of integers
3) Then we multiply each number in the set generated in step 1 by the MAX found in step 2, setting ones as 0 and zeros as MAX
4) Then we add the set generated in step 3 to our original set
5) Lastly we look for the MIN in the set generated in step 4
{=MIN((NOT(A1:A5000)* MAX(A1:A5000))+ A1:A5000)}
If you know the rough range of numbers, you can replace the MAX(RANGE) with a constant. This speeds things up slightly, still not enough to compete with the faster functions.
Also did a quick test run on data set of 5000 integers with formula being executed 5000 times.
{=SMALL(A1:A5000,COUNTIF(A1:A5000,0)+1)}
1.700859 Seconds Elapsed |
5,301,902 Ticks Elapsed
{=SMALL(A1:A5000,INDEX(FREQUENCY(A1:A5000,0),1)+1)}
1.935807 Seconds Elapsed |
6,034,279 Ticks Elapsed
{=MIN((NOT(A1:A5000)* MAX(A1:A5000))+ A1:A5000)}
3.127774 Seconds Elapsed |
9,749,865 Ticks Elapsed
{=MIN(If(A1:A5000>0,A1:A5000))}
3.287850 Seconds Elapsed |
10,248,852 Ticks Elapsed
{"=MIN(((A1:A5000=0)* MAX(A1:A5000))+ A1:A5000)"}
3.328824 Seconds Elapsed |
10,376,576 Ticks Elapsed
{=MIN(IF(A1:A5000=0,MAX(A1:A5000),A1:A5000))}
3.394730 Seconds Elapsed |
10,582,017 Ticks Elapsed
min() fuction exlude BOOLEAN and STRING values.
if you replace your zeroes with "" (empty string) - min() function will do its job as you like!
In Microsoft 365 you can use the new function MINIFS
=MINIFS(A1:E1;A1:E1;">0")
gives 1
=MINIFS(A1:E1;A1:E1;">1")
gives 18
*replace ; with , if using english version
All you have to do is to delete the "0" in the cells that contain just that and try again. That should work.

Resources