Formula to select highest date from array within specific constraints - excel

I'm looking for a formula to return one of six possible results based on which date (if any) is the highest out of all dates available that fall within a specific date range.
Consider the following layout:
Cell A1 has a fixed date (this is my lower constraint)
Cell A2 has a fixed date (this is my upper constraint)
Cells G5:K5 may contain dates or they may be blank.
If G5 and H5 both contain dates and both of those dates are between my dates in A1 and A2, then I want the result of my formula to identify which of those two is the most recent (it can show the date itself, the column header, a text string, doesn't matter as long as it is something different for each column)
If any of G5:K5 also contain other dates that fall outside of the window defined by A1 & A2 then those dates should be ignored.
If none of the dates are within the permitted range or all of the cells are blank then it can return a string like "not applicable" or an error that I can rewrite using IFERROR.
My dataset is pretty big (I'll be copying this formula down several hundred rows) so I would prefer to avoid using an {array} formula if possible - too slow. I've been staring at this worksheet long enough for my brain to have turned to mush, so if there is a straightforward approach to reaching my goal it is currently eluding me.
Any assistance greatly appreciated!

Figured it out in the end. It's not pretty, but it works.
This part returns the highest valid date:
MAX(IF(AND(G5>=$A$1,G5<=$A$2),G5,0),IF(AND(H5>=$A$1,H5<=$A$2),H5,0),IF(AND(I5>=$A$1,I5<=$A$2),I5,0),IF(AND(J5>=$A$1,J5<=$A$2),J5,0),IF(AND(K5>=$A$1,K5<=$A$2),K5,0))
And then by nesting it I can convert the results to a different text string depending on which column contains the "winner".
=IF(AND(MAX(IF(AND(G5>=$A$1,G5<=$A$2),G5,0),IF(AND(H5>=$A$1,H5<=$A$2),H5,0),IF(AND(I5>=$A$1,I5<=$A$2),I5,0),IF(AND(J5>=$A$1,J5<=$A$2),J5,0),IF(AND(K5>=$A$1,K5<=$A$2),K5,0))=G5,G5<>""),"CA",IF(AND(MAX(IF(AND(G5>=$A$1,G5<=$A$2),G5,0),IF(AND(H5>=$A$1,H5<=$A$2),H5,0),IF(AND(I5>=$A$1,I5<=$A$2),I5,0),IF(AND(J5>=$A$1,J5<=$A$2),J5,0),IF(AND(K5>=$A$1,K5<=$A$2),K5,0))=H5,H5<>""),"MX",IF(AND(MAX(IF(AND(G5>=$A$1,G5<=$A$2),G5,0),IF(AND(H5>=$A$1,H5<=$A$2),H5,0),IF(AND(I5>=$A$1,I5<=$A$2),I5,0),IF(AND(J5>=$A$1,J5<=$A$2),J5,0),IF(AND(K5>=$A$1,K5<=$A$2),K5,0))=I5,I5<>""),"BR",IF(AND(MAX(IF(AND(G5>=$A$1,G5<=$A$2),G5,0),IF(AND(H5>=$A$1,H5<=$A$2),H5,0),IF(AND(I5>=$A$1,I5<=$A$2),I5,0),IF(AND(J5>=$A$1,J5<=$A$2),J5,0),IF(AND(K5>=$A$1,K5<=$A$2),K5,0))=J5,J5<>""),"IQS",IF(AND(MAX(IF(AND(G5>=$A$1,G5<=$A$2),G5,0),IF(AND(H5>=$A$1,H5<=$A$2),H5,0),IF(AND(I5>=$A$1,I5<=$A$2),I5,0),IF(AND(J5>=$A$1,J5<=$A$2),J5,0),IF(AND(K5>=$A$1,K5<=$A$2),K5,0))=K5,K5<>""),"Other","Not Applicable")))))

I think I understand now. The following formula will get you the maximum date in the range G5:K5, subject to the condition that it be between the dates in A1 and A2. It will return "not applicable in the event that none of the dates meet the condition.
=IF(COUNTIFS(G5:K5,">="&$A$1,G5:K5,"<="&$A$2)<5,LARGE(G5:K5,1+COUNTIFS(G5:K5,">"&$A$2)),"not applicable")

Related

If target cell time (formatted as hh:mm:ss) is within a range, active cell displays text

Active cell is B2. Reference cell is A2, formatted as hh:mm:ss
B2 will display specific text depending on what time is manually inputted in A2. Specifically:
If manually inputted text in B2 is between 12:07:00 - 12:06:00, A1 will display text "Z1".
If manually inputted text in B2 is between 12:05:59 - 12:05:30, A1 will display text "Z2".
If manually inputted text in B2 is between 12:05:29 - 12:05:00, A1 will display text "Z3". etc.
Preference is for an IF function, and not a VLOOKUP. Have tried with a VLOOKUP but I'm obviously doing something wrong:
Undesired result 1 for VLOOKUP attempt:
Undesired result 2 for VLOOKUP attempt:
Thank you!
As a start, I can give you following example, which returns "AAA" in case the time is larger than 12h05.00, and "BBB" in other case:
=IF(B1>=TIME(12;5;0);"AAA";"BBB")
Obviously, you'll need to be able to combine conditions, like:
=AND(B1>=TIME(12;5;0);B1<=TIME(12;6;0))
(which you'll need to embed in your formula)
From here, you have a good start.
In case you still have issues, you can comment this answer.
I know you wanted an if statement however I fixed your vlookup problem for this. You would list the times in ascending order and use the formula =vlookup(a2,$E:$F,2,True). Your column d values are not useful here. This will look up the closest match for A2 that doesn't pass the amount in E.
example

Use SUMPRODUCT when field is blank from formula and dates

I have two columns in my excel, Date 1 in A and Date 2 in B. I'm trying to find the number of times Column B is greater than Column A. I'm using the formula =SUMPRODUCT(((B2:B5-$A$2:$A$5)>0)*1) and receiving an error. The error is due to the data in Column B is being pulled in from a formula, where my value_if_false is "". While the cell is blank, Excel sees this as data and will not execute my original formula.
If I go to B4 and delete the value, my original SUMPRODUCT will execute. I'd like not have to go back and do that. I've tried =SUMPRODUCT((NOT(ISBLANK(B2:B5-$A$2:$A$5)>0))*1) but it's returning 0. Any suggestions?
Try following array formula:
{=SUMPRODUCT((IF(IFERROR(VALUE(B2:B5);FALSE); B2:B5;0)>$A$2:$A$5)*1)}
Array formula after editing is confirmed by pressing ctrl + shift + enter
Writing "" (nul string) to a cell that is supposed to contain a number (such as a date) is never a good idea because it leads to problems like this one. The solution is in not writing a string (text) to a numeric field. Write zero instead, and then deal with the display of zeros via global settings or cell formatting.
Of course, any date would be greater than zero. If this leads to the wrong count the obvious remedy would be to make a second count of instances where zero is involved and deduct the result of the second count from the first, like, SUMPRODUCT(1)-SUMPRODUCT(2)
I guess if you wanted to stick with SUMPRODUCT and avoid array entry, you could try
=SUMPRODUCT((B2:B5<>"")*(B2:B5>A2:A5))
or to exclude anything except a number (which in this case would be formatted as a date)
=SUMPRODUCT(ISNUMBER(B2:B5)*(B2:B5>A2:A5))
is possibly better.
B4 contains "", not ="".

How to check if a cell is the 17th of any month

I have a column of dates (daily) and I want an IF statement that will check if the corresponding cell is the 17th of any month.
I'm happy with the syntax of if statements but am unsure how I should be using wildcards here. 'x'below can be any numerical value.
The cell in question looks like - 17/07/2019.
= IF( cell = 17/**/****,x,0)
Excel gets confused and tries to show me how to do maths without a formula.
If you already know that the date is not a text value you can use a simple formula like:
=IF(DAY(A1)=17,”x”,0)
The only issue is that your dates may be genuine Excel dates or text values. With data in A1, in another cell enter:
=IF(ISNUMBER(A1),IF(DAY(A1)=17,"X",0),IF(LEFT(A1,2)="17","X",0))

Formula returns #VALUE! when entered as array

I've put together an Excel spreadsheet to keep track of employees' time off using an array formula. The formula works for date ranges that are entered as "mm/dd - mm/dd", but I'd like it to also support single dates "mm/dd". However, I get a #VALUE! error when one of the cells in the range is of this format, even though the formula supports both formats when not entered as an array formula.
Example:
With the value "11/28" in cell B2, and a table of holidays in B31:B37, the following formula accurately calculates the number of work days as 1.
=SUM(IF(ISBLANK(B2),0,(IF(ISERR(FIND("-",B2)),NETWORKDAYS(B2,B2,$B$31:$B$37),NETWORKDAYS(LEFT(B2,5),MID(B2,FIND("- ",B2)+2,5),$B$31:$B$37)))))
If the value of B2 is "11/28 - 12/03", the formula returns 4.
I want this formula to work over a range of of cells for each employee, so I expand the range from "B2" to "B2:B10", and enter as the following array formula:
=SUM(IF(ISBLANK(B2:B10),0,(IF(ISERR(FIND("-",B2:B10)),NETWORKDAYS(B2:B10,B2:B10,$B$31:$B$37),NETWORKDAYS(LEFT(B2:B10,5),MID(B2:B10,FIND("- ",B2:B10)+2,5),$B$31:$B$37)))))
This formula works fine when every cell in the range is blank or has a date range of "mm/dd - mm/dd". However, if one of the cells has a single date "mm/dd", it throws a #VALUE! error.
What am I missing?
If there is no "-" in a given string then the FIND function will return a #VALUE! error for that string.
In general, there are two ways to resolve such issues. One is to include an error trap; the other, slightly longer though perhaps nevertheless preferable (IFERROR clauses are generally best avoided if possible), is to make suitable amendments to the strings being passed to MID and FIND such that this combination of functions does not error, whilst also ensuring that correct results are returned.
One such solution (still array-entered) is:
=SUM(IF(B2:B10<>"",NETWORKDAYS(LEFT(B2:B10,5),MID(B2:B10&"- "&B2:B10,FIND("- ",B2:B10&"- ")+2,5),$B$31:$B$37)))
Regards

Compare dates of two cells in excel

I have dates in E2 and F2 cells of an excel.The dates are in MM/DD/YYYY fromat.I want to apply validation in such a manner that date in F2 must be greater then dates in E2 .
In case of failure we should display an error.
I am using Microsoft Office 2007.
Help would be appreciated.
You could use conditional formatting?
In your case the background of one of the dates could turn red if the date is too low compared to another.
Quick google:
http://www.homeandlearn.co.uk/excel2007/excel2007s6p2.html
Should be quite easy doing =IF(F2>E2;"SUCCESS";"ERROR")
You can omit the "SUCCESS" and you only display the error should it fail. This will work as long as the fields are actually formatted as a proper date.
Updated code:
=IF(AND(NUMBERBLANK(E2:F2)=0;F2<E2);"ERROR";"")
What this does is: Check if both cells are filled, if they are chech if E is smaller than F, and write ERROR if that is the case.
To do this for the entire column you need to replicate the formula. For existing dates, just double click the lower right knob in the cell the formula is, and it SHOULD replicate down till the end of the row (if the row is next to the date). Other than that, just pull the knob down as far as you need it.

Resources