+ Reply to Thread
Results 1 to 12 of 12

Using LARGE to return Date with Conditional Statement

  1. #1
    Registered User
    Join Date
    07-21-2014
    Location
    Boston, MA
    MS-Off Ver
    2011
    Posts
    10

    Using LARGE to return Date with Conditional Statement

    Hello -

    I have a sample workbook attached. If it helps, I'm using Excel 2011 for Mac 14.7.1 (it's old, I know).

    The dummy data in the sample sheet is being used as a logbook.

    Screen Shot 2017-02-23 at 11.46.35 AM.png

    My intention is to have the date in A:A returned when B:B & C:C >2 within the last 90 days. LARGE gets me very close to what I intend, but not exactly. Google Sheets does something very similar with FILTER and works exactly as I'd like, but the version of Excel I have doesn't have FILTER. Maybe INDEX & MATCH would work better?

    Here is my current formula:
    =LARGE(IF((SUMIFS(B1:B8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2)*(SUMIFS(C1:C8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2), A1:A8), 3)

    Is this possible? And if so, does anyone have suggestions on how to do so?

    Thank you.
    Last edited by bcathell; 02-27-2017 at 09:57 AM. Reason: Removed external link to file.

  2. #2
    Valued Forum Contributor loginjmor's Avatar
    Join Date
    01-31-2013
    Location
    Cedar Rapids, Iowa
    MS-Off Ver
    Excel 2013
    Posts
    1,073

    Re: Using LARGE to return Date with Conditional Statement

    Hi -

    I'm not sure I fully understand what you're doing. The picture and the text don't really match up. Are you saying when the the value in column B plus the value in column C is greater than 2 AND the date is within the last 90 days from today, then you want the latest date that matches? In your example for 12/31/16, Cell B6 is 1 and C6 is 1. Neither is greater than 2 and when they're added together, they're still not greater than 2.

    The formula you posted uses the LARGE function, but it appears you are looking for the Third largest? It also references Cell E1, but I can't see what's in E1 from the picture you posted.

    Note, most people, including me, will not download a file from a link external to the Excel Forum for security reasons. So, if you want to attach a file, use the Go Advanced button just below and right of the Reply box, then scroll down to the hot link "Manage Attachments" and upload your file to the forum that way.
    ____________________________________________
    If this has solved your problem, please edit the thread title to add the word [SOLVED] at the beginning. You can do this by
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

    If I have been particularly helpful, please "bump" my reputation by pressing the small star in the lower left corner of my post.

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,600

    Re: Using LARGE to return Date with Conditional Statement

    (How to) Upload a Workbook directly to the Forum
    (please do not post pictures or links to worksheets)
    • Click Advanced next to Quick Post button at the bottom right of the editor box.
    • Scroll down until you see "Manage Attachments",
    • Click the "Choose" button at the upper left (upload from your computer).
    • Select your file, click "open", click "upload"
    • Once the upload is completed the file name will appear below the input boxes in this window.
    • Close the Attachment Manager window.
    • Click "Submit Reply"
    Note: Please do not attach password protected workbooks/worksheets
    Ensure to disable any Workbook Open/Autorun macros before attaching!
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    07-21-2014
    Location
    Boston, MA
    MS-Off Ver
    2011
    Posts
    10

    Re: Using LARGE to return Date with Conditional Statement

    Thank you both for the feedback. My apologies for the way I shared the workbook. I'll upload the workbook the way you describe.

    My formula is incorrect. What I intended to happen is to return the third largest date when the criteria is met. I changed the workbook to include the D and E column so you can see what I intended. It's another criteria that needs to be met.

    Your questions are close. I intended for the date to return when the SUM of B AND the SUM of C are both greater than 2 in the past 90 days. In another formula in my workbook (not posted here), SUMIFS works well to accomplish this goal; maybe it's not appropriate here? For example, if the data is:
    A B C D E
    1 2/24/16 2 1 DE DE
    2 5/29/16 1 1 DE
    3 6/22/16 1 1 DE
    4 8/27/16 1 2 DE
    5 11/30/16 2 1 DE
    6 12/31/16 1 1 DE
    7 1/9/17 1 1 DE
    8 2/23/17 1 1 DE

    I intended for the following to return 12/31/16:
    =LARGE(IF((SUMIFS(B1:B8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2)*(SUMIFS(C1:C8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2), A1:A8), 3)

    But if the data is:
    A B C D E
    1 2/24/16 2 1 DE DE
    2 5/29/16 1 1 DE
    3 6/22/16 1 1 DE
    4 8/27/16 1 2 DE
    5 11/30/16 2 1 DE
    6 12/31/16 1 1 DE
    7 1/9/17 1 1 DE
    8 2/23/17 1 DE


    I intended for the following to return 11/30/16 (because the SUM of the C column isn't >2 until 11/30/16, even though the SUM of the B column is >2 at 12/31/16):
    =LARGE(IF((SUMIFS(B1:B8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2)*(SUMIFS(C1:C8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2), A1:A8), 3)

    Now that I'm typing this, I see why LARGE is the incorrect formula to use. Maybe a mixture of MIN and MAX individually? I'm open to any way to make this work. I thought it would be simple
    Attached Files Attached Files
    Last edited by bcathell; 02-23-2017 at 06:49 PM.

  5. #5
    Registered User
    Join Date
    07-21-2014
    Location
    Boston, MA
    MS-Off Ver
    2011
    Posts
    10

    Re: Using LARGE to return Date with Conditional Statement

    Wow, this didn't format like I intended but I hope you understand what I was going after with the columns and rows.
    Quote Originally Posted by bcathell View Post
    A B C D E
    1 2/24/16 2 1 DE DE
    2 5/29/16 1 1 DE
    3 6/22/16 1 1 DE
    4 8/27/16 1 2 DE
    5 11/30/16 2 1 DE
    6 12/31/16 1 1 DE
    7 1/9/17 1 1 DE
    8 2/23/17 1 1 DE

  6. #6
    Valued Forum Contributor loginjmor's Avatar
    Join Date
    01-31-2013
    Location
    Cedar Rapids, Iowa
    MS-Off Ver
    Excel 2013
    Posts
    1,073

    Re: Using LARGE to return Date with Conditional Statement

    Hm. I'm still a little fuzzy on the logic here. Let's break your formula down:

    =LARGE(IF((SUMIFS(B1:B8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2)*(SUMIFS(C1:C8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2), A1:A8), 3)

    Let's start with the first SUMIFS:

    SUMIFS(B1:B8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)
    This is going to return the number 5 because the dates 11/30/2016, 12/31/2016, 1/9/2017, and 2/23/2017 are all within 90 days of today. And they have corresponding values of 2, 1, 1, and 1. So 2+1+1+1=5 which is ALWAYS going to be greater than 2.

    Let's look at the next SUMIFS:

    SUMIFS(C1:C8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)
    This is going to return the number 4 because, again, the dates 11/30/2016, 12/31/2016, 1/9/2017, and 2/23/2017 are all within 90 days of today. And they have corresponding values of 1, 1, 1, and 1. So 1+1+1+1=4, which is ALWAYS going to be greater than 2.

    So the first part is TRUE, and the second part is TRUE, so now we end with the last part of the formula:

    LARGE( the stuff we just looked at is TRUE so look at the WHOLE LIST OF A1:A8 and give me the 3rd largest date) Which is 12/31/2016. It will ALWAYS be 12/31/2016 based on the above logic.

    So walk me through this slowly. When you say the sum of column B is greater than 2, do you mean start summing at the first date that is within 90 days of today? In other words, that would start with Cell B5, which has a value of 2?

    Then you say the sum of Column C ALSO has to be greater than 2? Or are you saying the sum of column B PLUS the sum of Column C? In other words the first date that matches your criteria is 11/30/2016:

    Cell B5 is 2, Cell C5 is 1. B5 + C5 = 2+1 = 3. That is greater than 2. Is that what you're looking for?

    OR is it

    Cell B5 is 2, Cell C5 is 1. B5<= 2 (No Match) and C5 <2 (No Match) So then we go to the next cell A6, which is 12/21/2016.
    Cell B6 is 1, Cell C6 is 1.
    B5+B6=3 which is > 2 (Match) but C5 +C6 = 2 <= 2 (No Match) So only one condition is true, but not the other. So then we go to the next cell which is 1/9/2017.
    Cell B7 is 1, Cell C7 is 1.
    B5+B6+B7 = 4 > 2 (Match) C5+C6+C7 = 3 > 2 (Match) Now both conditions match so you want to return 1/9/2017 which is the first instance both conditions match? Is this correct?

    Sorry, I'm just not understanding what you're testing for.

  7. #7
    Registered User
    Join Date
    07-21-2014
    Location
    Boston, MA
    MS-Off Ver
    2011
    Posts
    10

    Re: Using LARGE to return Date with Conditional Statement

    Quote Originally Posted by loginjmor View Post
    Hm. I'm still a little fuzzy on the logic here. Let's break your formula down:

    =LARGE(IF((SUMIFS(B1:B8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2)*(SUMIFS(C1:C8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)>2), A1:A8), 3)

    Let's start with the first SUMIFS:

    SUMIFS(B1:B8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)
    This is going to return the number 5 because the dates 11/30/2016, 12/31/2016, 1/9/2017, and 2/23/2017 are all within 90 days of today. And they have corresponding values of 2, 1, 1, and 1. So 2+1+1+1=5 which is ALWAYS going to be greater than 2.
    Yes, this is correct.

    Let's look at the next SUMIFS:

    SUMIFS(C1:C8, A1:A8, ">="&TODAY()-90, D1:D8, "="&E1)
    This is going to return the number 4 because, again, the dates 11/30/2016, 12/31/2016, 1/9/2017, and 2/23/2017 are all within 90 days of today. And they have corresponding values of 1, 1, 1, and 1. So 1+1+1+1=4, which is ALWAYS going to be greater than 2.
    Yes, this was my intention. I have used the SUMIFS in part of another formula that does exactly as you describe. That formula that I'm using in the actual document is:

    =IF(C15="", "", IF(OR(AND(SUMIFS(Night_Takeoff,FlightDates,">="&TODAY()-89,FlightDates,"<="&TODAY(),Logbook!G3:G10000,"="&C15)>=3,SUMIFS(Night_Landing,FlightDates,">="&TODAY()-89,FlightDates,"<="&TODAY(),Logbook!G3:G10000,"="&C15)>=3),AND(OR(Certificate_Grade="Commercial Pilot", Certificate_Grade="Airline Transport Pilot"), ISNUMBER(MATCH(C15,T_Plane_More_1_Pilot,0))=TRUE,Logbook!$L$2>1500, $C$16="Current",SUMIFS(Logbook!L3:L10000, FlightDates, ">="&TODAY()-89, FlightDates, "<="&TODAY(), Logbook!G3:G10000,"="&C15)>=15,OR(AND(SUMIFS(Night_Takeoff,FlightDates,">="&DATE(YEAR(TODAY()),MONTH(TODAY())-5,DAY(TODAY())),FlightDates,"<="&TODAY(), Logbook!H3:H10000, "=Yes")>=3, SUMIFS(Night_Landing,FlightDates,">="&DATE(YEAR(TODAY()),MONTH(TODAY())-5,DAY(TODAY())),FlightDates,"<="&TODAY(), Logbook!H3:H10000, "=Yes")>=3),MAX(IF(C15=Training!J4:J25, Training!L4:L100))>DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()))))),"Current", "Not Current"))

    The above is a little sloppy and could be cleaned up, but it does exactly what I want for the conditional part of the statement. I would like to replace "Current" with the date (which I will try to explain below). Also, in the above formula, I used >=3, in this workbook, I used >2, they do the same thing, correct?

    [QUOTE]
    So the first part is TRUE, and the second part is TRUE, so now we end with the last part of the formula:

    LARGE( the stuff we just looked at is TRUE so look at the WHOLE LIST OF A1:A8 and give me the 3rd largest date) Which is 12/31/2016. It will ALWAYS be 12/31/2016 based on the above logic.[\QUOTE]

    Yes, I agree with you. And I understand why this isn't correct for what I'm trying to do.
    So walk me through this slowly. When you say the sum of column B is greater than 2, do you mean start summing at the first date that is within 90 days of today? In other words, that would start with Cell B5, which has a value of 2?

    Then you say the sum of Column C ALSO has to be greater than 2? Or are you saying the sum of column B PLUS the sum of Column C? In other words the first date that matches your criteria is 11/30/2016:

    Cell B5 is 2, Cell C5 is 1. B5 + C5 = 2+1 = 3. That is greater than 2. Is that what you're looking for?

    OR is it

    Cell B5 is 2, Cell C5 is 1. B5<= 2 (No Match) and C5 <2 (No Match) So then we go to the next cell A6, which is 12/21/2016.
    Cell B6 is 1, Cell C6 is 1.
    B5+B6=3 which is > 2 (Match) but C5 +C6 = 2 <= 2 (No Match) So only one condition is true, but not the other. So then we go to the next cell which is 1/9/2017.
    Cell B7 is 1, Cell C7 is 1.
    B5+B6+B7 = 4 > 2 (Match) C5+C6+C7 = 3 > 2 (Match) Now both conditions match so you want to return 1/9/2017 which is the first instance both conditions match? Is this correct?

    Sorry, I'm just not understanding what you're testing for.
    I think you're very close to understanding what I would like, I'm not putting it into words very well.

    The intended use for this is as a pilots (aviation) logbook. In order to maintain currency, a pilot needs three takeoffs (Column B) and three landings (Column C) within the previous 90 days. So, if I were to do this via a paper logbook, I would start at the most recent date, and count until I saw three takeoffs (B) AND three landings (C). When both conditions are met, I look at the date. So, the last part after "OR is it" is the correct logic for which I am trying to make a formula, except instead of starting 90 days ago and counting forward, I intended to start today and count backwards not to exceed 90 days. To reiterate, the bug formula from my actual workbook copied in here works perfectly to determine current versus not. I would like to go one step further and do what is described here and below.

    After the date is computed, I add 90 days to the date, but that part is easy enough I can handle (whatever the date is +90), therefore I didn't include it in the above formula(s).

    The final cell will say "Current until XX/XX/XXXX" or "Not Current". I also didn't include the words prior to the date because that one is also easy enough... I hope. "Current until "formula....

    Does this help? I am working late tonight, I won't see this until tomorrow afternoon, so I apologize ahead of time if my response is slow.

  8. #8
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,459

    Re: Using LARGE to return Date with Conditional Statement

    As per my understading:

    Get the most recent "DE" in column D (D7), then move backwards, sum B and sum C till sum B & sum C, >2 both?

    i.e,
    9/1 ; sum B = 1, sum C =1, DE, FALSE
    31/12 ; sum B = 2, sum C =2, DE, FALSE
    30/11 ; sum B = 4, sum C =3, DE, ok, get the date.

    Is it what you are looking for?
    Quang PT

  9. #9
    Valued Forum Contributor loginjmor's Avatar
    Join Date
    01-31-2013
    Location
    Cedar Rapids, Iowa
    MS-Off Ver
    Excel 2013
    Posts
    1,073

    Re: Using LARGE to return Date with Conditional Statement

    Hi -

    This was a pretty tough nut to crack. Basically you have to get Excel to look at the dates and landings in reverse order, just as you do it by hand. I got it to work, but I had to add two "helper" columns that accumlated the takeoffs and landings from the latest date back. Those helper columns also check to see if your DE criteria is met as to whether or not to add in the takeoffs and landings on a given date.

    Then, I used an Array formula of nested IF statements to pull out the list of dates that meet the criteria of 90 days or less with 3 or more accumulated takeoffs AND landings in that time period and return the latest date. That way you have the most current date that you can add 90 days to to determine how long they are current for.

    The meat of the array formula looks like this:

    MAX(IF((A2:A9>=TODAY()-90),IF((C2:C9>2),IF((E2:E9>2),A2:A9,""),""),""))

    It checks the dates to see if they are within 90 days of today. Then it checks the helper columns to see if both columns are greater than 2. If all three conditions are met, then the dates are stored in an array. MAX searches the array for the largest date (which will exclude the later dates that have 2 or less takeoffs and landings).

    To generate a message that the pilot is out of compliance, we have to wrap this whole thing in an IF statement, compare the above MAX formula to 0 (i.e., the pilot doesn't have enough takeoffs and landings in the last 90 days), and then display "Not Current" or display the date the pilot is current to (basically, copy the same formula above to the second half of the outside IF statement. That whole formula looks like this:

    =IF(MAX(IF((A2:A9>=TODAY()-90),IF((C2:C9>2),IF((E2:E9>2),A2:A9,""),""),""))=0,"Not Current",MAX(IF((A2:A9>=TODAY()-90),IF((C2:C9>2),IF((E2:E9>2),A2:A9,""),""),"")))

    Since it is an Array Formula, you have to press the Ctrl-Shift-Enter keys at the same time from the editing window to engage the array functionality. If you did it right, Excel adds curly braces {} around the formula. Attached is your spreadsheet with the helper columns and the above formula. To add more dates and takeoffs/landings, you will have to copy the accumulation formulas in columns C and E down and adjust the cell ranges in the above formula (which is located in Cell B11 in the attached spreadsheet.

    If you want to do away with the helper columns, you will need to use a VBA program to do the calculations. I couldn't figure out how to do it otherwise. Although, there are some VERY bright people on this forum. So maybe someone else might figure it out.

    Hope this helps.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    07-21-2014
    Location
    Boston, MA
    MS-Off Ver
    2011
    Posts
    10

    Re: Using LARGE to return Date with Conditional Statement

    I did a poor job of explaining the D column. The D column is a "constant", if you will, that is used elsewhere and I added it in here so I didn't forget. However, yes, that is exactly what I was looking for.

    Quote Originally Posted by bebo021999 View Post
    As per my understading:

    Get the most recent "DE" in column D (D7), then move backwards, sum B and sum C till sum B & sum C, >2 both?

    i.e,
    9/1 ; sum B = 1, sum C =1, DE, FALSE
    31/12 ; sum B = 2, sum C =2, DE, FALSE
    30/11 ; sum B = 4, sum C =3, DE, ok, get the date.

    Is it what you are looking for?

  11. #11
    Registered User
    Join Date
    07-21-2014
    Location
    Boston, MA
    MS-Off Ver
    2011
    Posts
    10

    Re: Using LARGE to return Date with Conditional Statement

    Quote Originally Posted by loginjmor View Post
    Hi -

    This was a pretty tough nut to crack. Basically you have to get Excel to look at the dates and landings in reverse order, just as you do it by hand. I got it to work, but I had to add two "helper" columns that accumlated the takeoffs and landings from the latest date back. Those helper columns also check to see if your DE criteria is met as to whether or not to add in the takeoffs and landings on a given date.

    Then, I used an Array formula of nested IF statements to pull out the list of dates that meet the criteria of 90 days or less with 3 or more accumulated takeoffs AND landings in that time period and return the latest date. That way you have the most current date that you can add 90 days to to determine how long they are current for.

    The meat of the array formula looks like this:

    MAX(IF((A2:A9>=TODAY()-90),IF((C2:C9>2),IF((E2:E9>2),A2:A9,""),""),""))

    It checks the dates to see if they are within 90 days of today. Then it checks the helper columns to see if both columns are greater than 2. If all three conditions are met, then the dates are stored in an array. MAX searches the array for the largest date (which will exclude the later dates that have 2 or less takeoffs and landings).

    To generate a message that the pilot is out of compliance, we have to wrap this whole thing in an IF statement, compare the above MAX formula to 0 (i.e., the pilot doesn't have enough takeoffs and landings in the last 90 days), and then display "Not Current" or display the date the pilot is current to (basically, copy the same formula above to the second half of the outside IF statement. That whole formula looks like this:

    =IF(MAX(IF((A2:A9>=TODAY()-90),IF((C2:C9>2),IF((E2:E9>2),A2:A9,""),""),""))=0,"Not Current",MAX(IF((A2:A9>=TODAY()-90),IF((C2:C9>2),IF((E2:E9>2),A2:A9,""),""),"")))

    Since it is an Array Formula, you have to press the Ctrl-Shift-Enter keys at the same time from the editing window to engage the array functionality. If you did it right, Excel adds curly braces {} around the formula. Attached is your spreadsheet with the helper columns and the above formula. To add more dates and takeoffs/landings, you will have to copy the accumulation formulas in columns C and E down and adjust the cell ranges in the above formula (which is located in Cell B11 in the attached spreadsheet.

    If you want to do away with the helper columns, you will need to use a VBA program to do the calculations. I couldn't figure out how to do it otherwise. Although, there are some VERY bright people on this forum. So maybe someone else might figure it out.

    Hope this helps.
    My apologies, work has been keeping me busy for the last few days. I've had time without an internet connection to play with this more, and I came up with an incredibly similar solution to you, also by adding two columns for a cumulative sum in reverse order. I also added another two columns, which your solution would eliminate the need for.

    I like what you did, it's cleaner than the way I came up with, and will alter what I did to use the suggestions you came up with.

    Thank you for your help!! It is very much appreciated!

    Here is how I did it:
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor loginjmor's Avatar
    Join Date
    01-31-2013
    Location
    Cedar Rapids, Iowa
    MS-Off Ver
    Excel 2013
    Posts
    1,073

    Re: Using LARGE to return Date with Conditional Statement

    Great! Thanks for the rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Multiple If statement to return a new date
    By cartica in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-18-2014, 02:16 PM
  2. Conditional IF and Vlookup Statement for a date range
    By geralde in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-08-2014, 09:27 AM
  3. [SOLVED] Return a date in 2nd Spreadsheet using an IF Statement
    By Touch9713 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-13-2013, 05:51 PM
  4. Replies: 2
    Last Post: 03-15-2013, 10:56 AM
  5. Question on How to return Maximum value out of a Conditional Statement
    By czou6 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-13-2013, 03:36 PM
  6. IF Statement to return value if a date is before another date
    By david1987 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-18-2012, 04:59 AM
  7. Conditional statement not recognizing a date???
    By edover in forum Excel General
    Replies: 3
    Last Post: 10-07-2008, 12:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1