I am importing into excel timestamps in the format YYYY-MM-DD HH:MM:SS.sss into column A of a new spreadsheet. I am trying to calculate the difference between two times.
So in column B I have the formula =RIGHT(A1,6) which gets the SS.sss value. In Column C I am taking the values away from each other - =B2-B1. This correctly calculates the gap between the two values.
What I want to do now, is create an IF statement =IF(C2<>0.02,"","Error"), to determine if the time gap is not the value is it supposed to be.
The problem is, that this IF statement always is evaluated as Error instead of the blank cell, even if the value in column C is 0.02.
Does anyone know why this might be happening?
Maybe you're comparing text 0.02 with value 0.02? Try:
=IF(VALUE(C2)<>0.02,"","Error")
The test in =IF(C2<>0.02,"","Error") with C2=0.02 evaluates to FALSE (ie C2 DOES equal 0.02), so 'of course' the third parameter is returned. I suspect you may want =IF(C2=0.02,"","Error").
Related
I am trying to find if there are any entries that have the same ID and also are within 30 mins of each other and the ID is always arranged in numerical order
The ID is in column A, date and time in column B, in column C and D i have these respectively
{=IF(AND(A2=$A$2:$A$7<>A2,OR(AND(0<B2-$B$2:$B$7<>B2,B2-$B$2:$B$7<>B2<0.020833),B2-$B$2:$B$7<>B2=0,AND(-0.020833<B2-$B$2:$B$7<>B2,B2-$B$2:$B$7<>B2<0))),"TRUE","FALSE")}
=IF(AND(A3=A2,C3="TRUE"),"",A3)
the output of the C column is always false, is there a fix for the formula or another way of approaching this?
Thank you ( sorry if this type of qn has already been answered )
I have made a similar Excel sheet, containing two important things:
The usage of the TIME() function, which makes it far more readable.
The usage of ABS(): if you want to compare the size of a difference, never forget to take the absolute value :-)
The sheet contains some characters 'a' and 'b' with some time entries, the formula checks if the value equals 'a' and if the time is within 10 minutes of 8h45. The used formula is:
=AND(A3="a",ABS(B3-TIME(8,45,0)) <= TIME(0,10,0))
Hereby a screenshot:
The colours are the result of conditional formatting, based on that same formula.
I have come up with
=IF(A2<>A1,"top no",IF(AND(A2<>A3,ABS(C2-C1)>TIME(0,30,0)),"bottom no",IF(AND(A2<>A3,ABS(C2-C1)<TIME(0,30,0)),"bottom yes",IF(ABS(C2-C1)>TIME(0,30,0),"mid no","mid yes")))) and =IF(ISERROR(MATCH("*no*",K2)),"",A2) to solve my problem
I'm pulling my hair right now trying to achieve that without VBA.
I do not want any VBA and I know It's easy to do with barely more than two lines of vba code.
Here is a simplified template of the type of table I'm working with.
The objective is : With one formula Return the column where the three specified values are matched. The value Im searching for will be somewhere on the sheet where the formula will be.
Just put them as value in the formula if you have one that can achieve that.
Best regards and thanks in advance if anyone help me restore my mental sanity.
Assuming a data setup like this:
This formula is in cell F1:
=SUMPRODUCT((B1:C1&B2:C2&B3:C3=F2&F3&F4)*(COLUMN(B1:C1)))
Adjust ranges to suit your actual data
Explanation:
It combines values of the columns' rows into a single string (so in this example, it would be {"KPI ADATEDATA TYPE","KPI BDATEDATA TYPE"})
It then compares those results to a combined string of what you're looking for: "KPI ADATEDATA TYPE" converts results to TRUE/FALSE so you end up with {TRUE,FALSE} (because the first combined string with KPI A matches)
Then it gets all possible column numbers of the results: {2,3} in this case for columns B and C
The multiplication then converts the TRUE/FALSE's into 1s and 0s respectively so you end up with {1,0}*{2,3}
Because there can assumably only be a single match, this results in the correct column number being the only value to be multiplied by 1, so results are {2,0}
The SUMPRODUCT then sums the results, and since there is only a single non-zero number, it must be the column index.
I am not into Excel and I have this problem trying to sum the values of 2 different column and put this result value into a cell.
So basically I have the D column containing 2 values (at the moment only 2 but will grows without a specific limit, I have to sum all the values in this column). These value are decimal values (in my example are: 0,3136322400 and 0,1000000000).
Then I have an I column containing the same type of value (at the moment only one but also the values in this column can grow without a specific limit...in my example at this time I have this value −0,335305)
Then I have the K3 cell where I have to put the sum of all the valus into the D column and all the values into the I column (following my example it will contain the result of this sum: 0,3136322400 + 0,1000000000 −0,335305.
Following a tutorial I tried to set this simple forumla in the K3 cell:
=SUM(A:I)
The problem is that in this cell now I am not obtaining the expected result (that is 0.07832724) but I am obtaining this value: 129236,1636322400.
It is very strange...I think that maybe it can depend by the fact that the D and the I column doesn't contain only number but both have a textual "heder" (that is the string "QUANTITY" for both the cells). So I think that maybe it is adding also the number conversion of this string (but I am absolutly not sure about this assertion).
So how can I handle this type of situation?
Can I do one of these 2 things:
1) Adding the column values starting from a specific starting cell in the column (for example: sum all the values under a cell without specify a down limit).
2) Exclude in some way the "header" cells from my sum so the textual values are not considered in my sum.
What could be a smart solution for my problem? How can I fix this issue?
The sum function can take several arguments.
=sum(d2:d10000, i2:I10,000, more columns )
This should remove the header from the calculation.
If you turn your data into an Excel Table (Insert > Table), you can use structured referencing to address a table column, excluding the header.
=SUM(Table1[This Header],Table1[That Header])
Then you don't need to reference whole columns. If you add new data to the table, the formula will take that into account.
I have the following formula to return the value of the last value in a column:
=LOOKUP(2,1/(D:D<>""),D:D)
What I need now is to return the value of the cell adjacent to it as well. (It will not necessarily be the last value in that column and the info in Column D could have duplicates.
If your data looks like this:
A 1
A 2
A 3
B 4
B 5
B 6
C 7
To get last value this will do the trick:
=INDIRECT("B"&COUNTA(A:A))
And to get last where value is A:
=INDIRECT("B"&MATCH("A",A1:A7,0)+COUNTIF(A1:A7,"A")-1)
Just use next column:
=LOOKUP(2,1/(D:D<>""),E:E)
Ok, So I have found an answer by playing around with array formulas.
The problem was that this is a stock control sheet where there are changes made at multiple times, each recorded in the next available row. There is always a date (Column E) but not necessarily a Supplier, as it might be stock moving out. When a Supplier delivers, the Supplier name is recorded in Column D. In D1 the last supplier is then shown with the following formula.
=LOOKUP(2,1/(D:D<>""),D:D)
I want to then see what date it was last received. The formula I found that works is as follows (Array Formula):
=INDEX(E:E,MAX(IF(D:D=D1,ROW(D:D)-ROW(INDEX(D:D,1,1))+1)))
This is generally how I do it:
=XMATCH(FALSE,ISBLANK(A:A),0,-1)
This is what each part does:
Parameter
Explanation
FALSE
Instructs Excel to find the first instance of FALSE that it finds
ISBLANK(A:A)
Takes in the column A:A and notionally assigns a value to every item in the column
0
Means we want an exact match. Probably not necessary to put in, but I think it's good practice anyway
-1
Instructs Excel to start the search at the bottom/right of the range and work up/left. If you change this to 1 (the default), Excel will begin the search at the top/left and work down/right
So, taken together, this will search from the bottom of the column A:A, until Excel finds the first cell that is not blank, and return that cell.
Also, yes, this equation can be changed to a row format (e.g. 1:1), and can take a smaller range (e.g. A1:A20), but it cannot take a 2-dimensional range (e.g. A1:B20).
As a practical matter, this approach is much faster than other approaches (and much faster than you'd think, given it's evaluating against every row/column in the range), and won't get fooled by columns that have empty spaces in them (like with a COUNTA style approach).
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.