+ Reply to Thread
Results 1 to 17 of 17

Find earliest date based on certain criteria

  1. #1
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Find earliest date based on certain criteria

    Ok so let me set this up. I have 2 columns:

    Project Date Start
    NY 1/14/2009
    Cali 5/6/2010
    NY 7/2/2009
    NY 8/2/2010
    Cali 3/2/2009
    Cali 10/2/2011

    Ok, so what function can I use that will output the earliest "Date Start" but using the criteria of "Project". I want to make sure that when this list grows to 1,000+ that I don't have to go back through and create a new formula each time. The objective is to have Tab 1 show:

    Project Date Start
    California 3/2/2009
    New York 1/14/2009

    So on and so forth for new projects as they come on.

    Things I have tried and might just be scripting wrong (Keep in mind that for me "Project" is column B and "Date Start" is column E:

    =IF((IF(T(B:B)="cali",COUNT(E:E),"")),MIN(E:E),"")

    I have found several ways to pull the lowest date, but not when I need it to reference it based on the criteria of "Project". Anything you can offer would be great! Thanks!
    Last edited by SeanKosmann; 01-26-2010 at 11:32 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find earliest date based on certain criteria

    Simplest thing would be to use a Pivot Table - use a Dynamic Named Range as source (see link in sig. for more info) ... set Project as Row Field / Label and Start Date as Data Field set to MIN format as date.

  3. #3
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Find earliest date based on certain criteria

    I will look into the pivot table, but is there a formula way to accomplish this?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find earliest date based on certain criteria

    Yes but unless the source data is first sorted it will be more expensive long term...

    If your data resides on Sheet2 and your "final" project listing on Sheet1 then with first project name listed in say A2:

    Please Login or Register  to view this content.
    that in red is imperative... also note Arrays are inefficient and keeping ranges "lean" is a must for the sake of overall workbook performance.

    Of course were your source data (sheet2) sorted first by project and latterly by date (asc) you could then dispense with the Array and revert to far more basic and efficient INDEX/MATCH function.

    I would still strongly advise the PT route... I suspect you may find you get a lot of unexpected gains from this approach in the long run (ie reporting power for no effort)

  5. #5
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Find earliest date based on certain criteria

    I'm trying that formula presented and it's coming back being flagged that it ran out of resources (I'm assuming this is why the PT is better).

    Yes, the information will already be in sorted by the project name, the problem is that the formulas needs to be able to go all the way down the column and not be bound by a defined range, because as new projects come on, it will shift the cells.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find earliest date based on certain criteria

    Quote Originally Posted by SK
    I'm trying that formula presented and it's coming back being flagged that it ran out of resources (I'm assuming this is why the PT is better).
    It shouldn't ... did you change the references such that you are using entire column references ?
    If so, as advised, don't - in XL2007 this means you're processing over 2 million cells per calculation (!) ... pre XL2007 this would generate #NUM! errors (ie not permitted)

    You say the data is sorted by Project, is it sorted by Date also ?

    Regards expanding ranges - note my point in post # 3 re: Dynamic Named Ranges.
    Last edited by DonkeyOte; 01-25-2010 at 01:20 PM. Reason: missing "e"

  7. #7
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Find earliest date based on certain criteria

    No the data is not sorted by Date because Project NY 1 might go off in the third quarter of this year, where as Project NY 2 might go off next week. And each project can have up to 150 sites or more.

    Let me switch all my formulas over to the Dynamic Named Ranges, I haven't used those before, I don't know why....... it would have made a lot of things easier/faster! So let me see if that fixes the problem at hand.

  8. #8
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Find earliest date based on certain criteria

    Ok, so now, I have created my dynamic name ranged:

    =OFFSET(Value!$B$1,0,0,COUNTA(Value!$B$1:$B$200),1)

    This is showing what I want, where there is information, however, it is still going down the column showing #value! where there is no information for it to pull yet. Did I type it in wrong?

    *** I just changed COUNTA to MATCH, and changed the end accordingly, but still getting the same issue
    Last edited by SeanKosmann; 01-25-2010 at 01:34 PM.

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find earliest date based on certain criteria

    I confess I'm struggling to visualise exactly...

    You would potentially get a #VALUE! error with the MIN formula if you did not confirm as an Array (ie see text in red) - ie you must use CTRL + SHIFT + ENTER ... that said have you created a Named range for Column E also ?

    Here would be my suggestion... without knowing remaining particulars of your file...

    If we assume that Project column is never empty when the row is in use (ie no interspersed blanks - as implied by your earlier use of COUNTA) then:

    Please Login or Register  to view this content.
    You can then either

    a) create a Pivot Table and use _DATA as reference (create accordingly)
    (assumes you have header values in row 1 on Value sheet in Columns B:E)

    b) use the earlier array but adapt per the above name range, eg:

    Please Login or Register  to view this content.
    becomes

    Please Login or Register  to view this content.
    In the above you will note I used INDEX & MATCH to create the Dynamic Name rather than OFFSET - this is purely because OFFSET is Volatile and INDEX is not thus I prefer the INDEX approach (it's a personal thing)

    Re: use of REPT("Z",255) - this is technique for finding last values of a given data type (I've assumed Project Names are always text strings (ie never numbers)) - for a guide on "finding last value" techniques see Bob Phillips' white paper: http://www.xldynamic.com/source/xld.LastValue.html

    If you're still struggling it might be an idea to post a non-confidential version of your file so we can see what you're using exactly.

  10. #10
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Find earliest date based on certain criteria

    Ok, I will keep working on your comments and see if I can bring it together.

    As for posting the actual document, I can completely do it as everything in it is currently theoretical values that I have created for the sake of testing/breaking it. The problem I'm running into is when trying to upload it, the file is too big, I would have no problem emailing it over to you if you would like? Unless there is another way of uploading that I don't know about.

    Thank you for all of your help by the way, I appreciate it!

  11. #11
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find earliest date based on certain criteria

    Have a crack working through the above - if it doesn't work all we need see in your sample file is the Value sheet and the sheet on which you're trying to perform the calcs.

    If there are formulae in Column B on the Values sheet we'd need to know what the formula is - the formulae need not be in the sample file (so as to reduce linkage - number of sheets required in sample kept to a min)

    In terms of # of rows etc - we're really only need to see a subset of say 1000 rows and a few projects to validate what's happening ... but to reiterated, condescending as it may sound it would be worthwhile walking through on your own in the first instance ... if you get it working it will be have been time well spent I'd say.

  12. #12
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Find earliest date based on certain criteria

    No I completely agree, I'm going to work through this tonight, it might be easier to try and start from the beginning, because I have formulas like =proper that are pulling text strings across various tabs so that as I input in the first tab, it shows up on the rest.

    So I will start a new spread sheet tonight trying to setup the various columns using all dynamic ranges, as it seems that will reduce the computing required SIGNIFICANTLY. So I'll post tonight or tomorrow as I break everything again.

  13. #13
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Find earliest date based on certain criteria

    Good morning all. So last night I went through and recreated the entire file because I realized by keeping is simple I was making it too big, so here is the reduced version. I tried the scripting from yesterday and still fell short. No matter what criteria I used, it still returned the overall lowest date.

    Please see file attached, as you will see I tried several different things to solve the issue. The end result is that on the first tab under "Start Data Services" I need to have it return the earliest date for the respective "Projects". All the dates are on the second tab "Data".

    I know there is no dynamic ranges, I'm planning on adding those in later, I'm just still trying to understand/learn how that scripting works.
    Attached Files Attached Files

  14. #14
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find earliest date based on certain criteria

    OK, the column references have changed slightly from before but referring solely to the MIN function...

    If I alter references from E to K and alter sheet name from Sheet2 to Data and enter below into I3 as an Array

    Please Login or Register  to view this content.
    and copy down it generates expected results.

    If the Data tab always has transactions sorted by Project (ascending order) as implied you could avoid Array if preferred and revert to a standard MIN using INDEX to determine the appropriate range against which it should be applied, eg:

    Please Login or Register  to view this content.
    (in all of the above we're assuming that the Project listed in B always exists on Data sheet and always has a date value assigned - ie no pre-emptive error checks are required)

  15. #15
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Find earliest date based on certain criteria

    I typed in both formulas, I got the 2nd one to work, but not the first.

    You will notice I added it to the front page. The VA and Roanoke did not pick up (They are instead just taking the lowest overall date). And when i went back to data and added in another New York with an earlier date, I was not picked up. Thoughts?
    Attached Files Attached Files

  16. #16
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Find earliest date based on certain criteria

    Quote Originally Posted by SK
    The VA and Roanoke did not pick up (They are instead just taking the lowest overall date). And when i went back to data and added in another New York with an earlier date, I was not picked up. Thoughts?
    Quote Originally Posted by D.O
    If the Data tab always has transactions sorted by Project (ascending order) as implied you could avoid Array if preferred and revert to a standard MIN using INDEX to determine the appropriate range against which it should be applied...
    In the latest attachment the data is no longer sorted by Project thus the non-array MIN(INDEX based approach is not viable.

    Please post a version in which you have added the suggested Array without achieving desired results
    (remember CTRL + SHIFT + ENTER to commit the formula, not just Enter like "normal" formulas)

  17. #17
    Registered User
    Join Date
    01-25-2010
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Find earliest date based on certain criteria

    Ok, corrected data so that it is grouped and alphabetical, and it's working.

    THANK YOU!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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