This formulae "works", but it seems a bit long winded. Can anyone suggest an "easier" formulae. It returns the value in the 5th Column to a date in the 1st column which is called from a separate (and discrete) worksheet. If there is no data in the 5th column (because we haven't reached or passed that date), then the latest available data is called ($A$20, is the "calling date, on a current worksheet):-
IF(VLOOKUP($A$20,'[FTSE100.xlsx]Meteor Step Down
Plans'!$A$18:$E$2828,5)="",VLOOKUP(HLOOKUP(A20,'[FTSE100.xlsx]Meteor Step
Down Plans'!$A$18:$A$2628,MATCH(TRUE,INDEX(ISBLANK('[FTSE100.xlsx]Meteor
Step Down Plans'!$E$18:$E$2828),0,0),0)-1),'[FTSE100.xlsx]Meteor Step Down
Plans'!$A$18:$E$2828,5),VLOOKUP($A$20,'[FTSE100.xlsx]Meteor Step Down
Plans'!$A$18:$E$2828,5))
The formula is in a different workbook to the data. The formula is used to determine the last value in an array, the first column of which is a date range (01/01/2000 to 31/12/2027....say) The required data is in column 5. Entries may be up to date (i.e. the last entry was made today, therefore it will pickup todays value. The last entry may have been several days (weeks) ago, therefore it will pick up the last value in the designated column (column 5). I don't see why it can't go into a named range, as the array size is fixed. Does that help?
Thanks Ron, nearly there. That works beautifully for "missing" dates in the array. i.e. when Saturday and Sunday dates are missing, it finds the value (in column 5) of the previous Friday. However (and there is usually a "however"), if $A$20 is a date in advance of the date of the last data in the array i.e. column 5 is blank at that date, your formulae returns 0 (zero), instead of the data as at the last date that data has been entered. i.e. enter 02/04/2018 and your formulae returns 0, not the data at the last date available 28/02/2018. Is that a little more clear?? (Thank you anyway, for spending the time - I'm still trying to work out how your formulae works as it does. Is the "/" significant (other than being a "divide by" symbol, if so it's something I've never come across before? Regards...........Mike. P.S. The dates in the array (Column 1) are all in from 2016 to 2027 (excluding weekend and bank holidays), and are arranged in ascending order i.e. from 01/01/2016 to 31/12/2027
Ron - Sorry mate, buy I can't see a "second" formulae???
If I understand what you want to do correctly, (and that is hard to do since you give NO examples of your data, actual output or desired output), try:
=LOOKUP(2,1/((myDate>=A:A)*(LEN(A:A)>0)),E:E)
If it is the case that you have dates in column A and no entries in Column E, then you might have to do something like:
=LOOKUP(2,1/((myDate>=A:A)*(LEN(A:A)>0)*(LEN(E:E)>0)),E:E)
Of course, you will have to modify the cell references and named range to refer to the proper workbooks and cell.
Possibly something like:
=LOOKUP(2,1/(($A$20>='[FTSE100.xlsx]Meteor Step Down Plans'!$A$18:$E$2828)*(LEN('[FTSE100.xlsx]Meteor Step Down Plans'!$A$18:$E$2828)>0)),'[FTSE100.xlsx]Meteor Step Down Plans'!$E$18:$E$2828)
This should return the item from Column E that is either at or above the same row as myDate in Column A. If myDate does not exist in column A, it will match the nearest earlier date in Column A and return from that row in Column E.
In the second version of the formula, it also checks that there is an entry in Column E matching the column A date, and, if not, it will look above.
Related
I am looking for some guidance in looping through a function in Excel within a table without running into a circular reference error. I've spent quite some time trying out COUNTIF, MATCH, Essentially, I need to create a function/formula for the "Desired Date" column so that it takes value from the "Original Date" column and changes the value based on the following parameter:
If a date in the Original Date column does not exist within the previous values of the Desired Date column, it will list the exact date. I've already solved this part with IF and COUNTIF functions.
If a date in the Original Date column already exits within the previous values of the "Desired Date" column, it will add +1 day(s) until all the values within the Desired Date column have unique dates.
Here's what I would like the function to do:
Row 1 contains the original date value as 8/1, since no other values exist in the desired row column, it will return 8/1.
Row 2 contains the original date value as 8/1, but since row 1 of the desired date value already contains value 8/1, it will add +1 day so it becomes 8/2.
Row 3 contains the original date value as 8/1, but since row 1 & row 2 of the desired date contain the value, it will add +2 days, so it becomes 8/3.
Row 6 contains the original date value as 8/3, but since row 3 of the desired date contain the value, it will add +1 day so it becomes 8/4.
If at any given point a date within the original date changes, the values in desired dates should change accordingly by adding a variable amount of days until all values within the Desired Dates column are unique.
Row
Original Dates
Desired Dates
1
8/1/2021
8/1/2021
2
8/1/2021
8/2/2021
3
8/1/2021
8/3/2021
4
8/12/2021
8/12/2021
5
8/12/2021
8/13/2021
6
8/3/2021
8/4/2021
7
8/4/2021
8/5/2021
8
8/3/2021
8/6/2021
9
8/13/2021
8/14/2021
I've spent well over 9 hours on this issue so any help at this point would be very much appreciated. I wouldn't mind using VBA but a function would be preferred for compatibility purposes.
Thank You!
One approach might be to generate dates starting with the date in the first column but ignoring any dates that have already been used (countif>0), then pick the lowest of these:
=LET(maxdate,$D$2,
startdate,B2,
seq,SEQUENCE(maxdate-startdate,1,startdate),
MIN(IF(COUNTIF(E$1:E1,seq),maxdate,seq)))
or slightly shorter
=LET(maxdate,$D$2,
startdate,B2,
seq,SEQUENCE(maxdate-startdate,1,startdate),
MIN(IF(COUNTIF(E$1:E1,seq)=0,seq)))
If you don't have Excel 365, you can use Row instead of Sequence:
=MIN(IF(COUNTIF(E$1:E1,ROW(INDEX(A:A,B2):INDEX(A:A,$D$2)))=0,ROW(INDEX(A:A,B2):INDEX(A:A,$D$2))))
entered as an array formula using CtrlShiftEnter
EDIT
If you wanted to concatenate as in your comment, you wouldn't be able to use Min (because the values wouldn't be numeric) but you could use index/match to find the first available date for a particular person:
=LET(maxdate,$D$2,
startdate,A2,
name,B2,
seq,SEQUENCE(maxdate-startdate,1,startdate),
seqName,seq&name,
INDEX(seqName,MATCH(0,COUNTIF(H$1:H1,seqName),0)))
If you wanted to make the dates appear as a date rather than a number, you could wrap them in Text:
=LET(maxdate,$D$2,
startdate,A2,
name,B2,
seq,SEQUENCE(maxdate-startdate,1,startdate),
seqName,TEXT(seq,"mm/dd/yy")&name,
INDEX(seqName,MATCH(0,COUNTIF(H$1:H1,seqName),0)))
I am trying to lookup a part number in a separate table array, the same value could be in multiple rows. The formula should find each instance of the value in the other table, move to a date column and determine which months the value exists in and which row it belongs to. The entire table B3:F15 should be automated. I have attached an image with proper explanation of what I am trying to accomplish if at all possible.
The formulas would be entered into B3:F15. These are the cells where the data will get pulled into. Each row will search for its corresponding Part Number in column A. I.e, B3 to F3 is only looking for A3 data. The rows are used to determine if a Part number in L2:P4 matches their row value in Column A and if was used in that month belonging to months B2:F2. If the Part number was used in the corresponding month then it will output the Plant # from Column I. In some cases the Part numbers in L2:P4 can exist in multiple rows, but they are unique to each column.
As an example I have manually filled in data for PN1001 and PN1021. For PN1001, this belongs to B3:F3. Each cell in B3:F3 will search the array L2:P4 and realize it is found only once and in M4, so it will look at the dates from its row, J4 and K4, and determine which months it was used in. Since it was used in Jan, Feb, and Mar, it will output the Plant # into D3, E3, F3. In the example of PN1021 it is the same but in this case PN1021 exists in L2 and L4, so it will take the date of J2,K2, and J4,K4.
Some Part numbers can be a combination of letters and numbers, some may just be numbers.
In terms of how to build the formula I am not sure what combination of Index/Match/Lookup I should be using. My theory is that each cell in B3:F15 would include a formula that be =MATCH(Lookup(columnA with L3:P4)) (but how do you get it to lookup multiple instances??) Some research lead me to use this concept to find multiple instances and point to the row #.
SMALL(IF(Lookup Range = Lookup Value, Row(Lookup Range),Row ()-# of rows below start row of Lookup Range)
Once I can find each instance, then Index the row and compare if the cell in B3 is greater than J3 and less than K3 to determine the months which should have a value entered. IFYES, then output column I from the row number.
If you have any better solutions or ideas to perform this action then please provide feedback. Thanks in advance for the support.
I think the formula below will do what you want. I created a table out of your I1:P4 data, and used structured references, as I find it easier to follow.
B3: =IFERROR(
INDEX(partsTbl,
MAX(
($A3=partsTbl)*
(B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))*
(B$2<DATE(YEAR(partsTbl[[Test Finish Date]:[Test Finish Date]]),MONTH(partsTbl[[Test Finish Date]:[Test Finish Date]])+1,1))*
ROW(partsTbl)-ROW(partsTbl[#Headers])),
1),
"")
$A3=partsTbl returns a 2D array like {FALSE,FALSE,TRUE,FALSE;FALSE,FALSE, …} to find the part number in the table
Since your start/finish dates in the partsTbl are not always at the beginning/end of the month, we need to convert them to such before we compare the dates in B2:F2
(B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))
And similar for the end of the month.
We now have a 2D-array of {FALSE,FALSE,TRUE,FALSE...} where the TRUE matches the part number as filtered by the dates.
ROW(partsTbl) returns a matching array of the row numbers in the table (and we subtract the row number of the Header row to determine the row within the data).
When we do our multiplication, we then get an array where the largest value will be the desired row
INDEX, referencing column 1, will then return the appropriate Plant #
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).
I have an Excel spreadsheet like so:
A B
27/03/2015 Riddor
28/03/2015 Text
09/03/2015 Bees
What I am trying to do is search my column B for the word Riddor using this function:
=IF(ISERROR(MATCH("Riddor",Statistics!B:B,0)),"No Match",TODAY()-MIN(Statistics!B:B))
Within this function if the value Riddor is not found I want to show 'no match' else if the value is found I want to identify the most recent occurrence of the value Riddor in my column where its date in column A is the most recent from today. I then want to count the number of days.
So for instance my value Riddor in column B has a date of 27/03/2015. The number of days from this date to today is 5, however if I add another Riddor with a more recent date like so:
27/03/2015
31/03/2015
then I want my day count to show 1 day instead of the previous 5 days.
Can someone please show me where I am going wrong and what to do to get this working?
You will need to use a formula as defined below
Note that the flower brackets indicate that you are using this as a range formula which means you will need to hit Shift+Control+Enter and when you click on that Cell it will create the flower brackets in the end.
The below formula will retrieve the MAX Date the next part is quite simple you need to subtract from today to arrive at the difference in days. Preferably do it in another cell. I have accounted for different sheets in a modified formula at the bottom of this post. But you can test the below on the same sheet and then copy over the cell to another sheet to have it dynamically correct to account for sheet if you like. Either ways the below is tested with all events and is working
{=IF(COUNTIF(B:B,"Riddor")=0,"No Match",IF(COUNTIF(B:B,"Riddor")=1,INDIRECT("A"&MATCH("Riddor",B:B,0)),MAX(IF(B:B="Riddor",A:A))))}
Explanation
Part I - =IF(COUNTIF(B:B,"Riddor")=0,"No Match" Counts if there are any occurance of the word Riddor in that Range
Part II - IF(COUNTIF(B:B,"Riddor")=1,INDIRECT("A"&MATCH("Riddor",B:B,0)) this part accounts if there is only once occurance of the word Riddor then it uses the Match function to retrieve the date from the A Column. It would be easier with VLOOKUP but I'm assuming you dont want to change the Column Order for A & B
Part III - MAX(IF(B:B="Riddor",A:A)))) This where the Range formula is actually required. It checks in the Range B:B and Retrieves all the Dates where the B Column Matches "Riddor" and then Finds the Max date in that subset Range which would be the date closest to today's date.
Tested and Working perfectly in sample provided by your even with Multiple instances of Riddor.
Formula Accounting for the difference in Sheets not tested yet.
{=IF(COUNTIF(Statistics!B:B,"Riddor")=0,"No Match",IF(COUNTIF(Statistics!B:B,"Riddor")=1,INDIRECT("Statistics!A"&MATCH("Riddor",Statistics!B:B,0)),MAX(IF(Statistics!B:B="Riddor",Statistics!A:A))))}
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.