+ Reply to Thread
Results 1 to 20 of 20

Query finding earlist date among common numbers

  1. #1
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Query finding earlist date among common numbers

    I have a query set up to pull all data from a table that has a "PSAT" result in the STATUS column. The results or columns I am pulling are the STATUS, TP_NO, TESTDATE and TWR_NO. The TP_NO's are often duplicated many times and what I am trying to find with the query is only the earliest dates that recieved a PSAT result for each test number.

    Here is the code I currently have:
    Please Login or Register  to view this content.
    Attached is an example of the result I get & the results I want

    ProcedureLog.xlsx

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    I would think:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Re: Query finding earlist date among common numbers

    Quote Originally Posted by Arkadi View Post
    I would think:

    Please Login or Register  to view this content.
    I get an error message stating:

    You tried to execute a query that does not include the specified expression as part of an aggregate function or grouping.

    Possible cause:


    You did not enter an aggregate function in the TRANSFORM statement.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    Ok... how about:
    Please Login or Register  to view this content.
    Nevermind.... will still return all the records

  5. #5
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Re: Query finding earlist date among common numbers

    If it helps, I posted the question on another forum and got the following example to try, but ultimately I end up getting the same error as posted above.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Re: Query finding earlist date among common numbers

    Quote Originally Posted by Arkadi View Post
    Please Login or Register  to view this content.
    Still returning all the data.

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    Yeah made a mistake sorry... try this one though, it should actually work:

    Please Login or Register  to view this content.
    Sorry about the earlier misleading attempts, didn't think it through and sometimes things seem simpler than they are. :/
    Last edited by Arkadi; 03-27-2015 at 11:09 AM.

  9. #9
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Re: Query finding earlist date among common numbers

    Quote Originally Posted by Arkadi View Post
    Yeah made a mistake sorry... try this one though, it should actually work:

    Please Login or Register  to view this content.
    Sorry about the earlier misleading attempts, didn't think it through and sometimes things seem simpler than they are. :/
    Ahh... So VERY close! It's now paring it down like I'm looking for, however it's excluding a handful of the TP numbers. All the criteria is there in the selected fields, it's just not returning the results for them.

  10. #10
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Re: Query finding earlist date among common numbers

    Ok, I pulled the WHERE line and the results it gave me made me realize that what it's doing is if an earlier date exists in the TestDate field that is listed as anything other than "PSAT" then it just doesn't return a result at all. So, if I have a REJECT on 5/5/13 and then a PSAT on 5/8/13 under the same TP_NO then it just doesn't return a result insted of finding the next earliest PSAT.

    Hope that makes sense...

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    Hmmm... I put the data you gave as an example into a table and I got the results you had expected... I assume your case now is a larger data set... any chance the testdate is null on the ones not coming down? can you give me some data that is not coming down as intended? I can try to duplicate the issue and troubleshoot.

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    Quote Originally Posted by xrajncajnx View Post
    Ok, I pulled the WHERE line and the results it gave me made me realize that what it's doing is if an earlier date exists in the TestDate field that is listed as anything other than "PSAT" then it just doesn't return a result at all. So, if I have a REJECT on 5/5/13 and then a PSAT on 5/8/13 under the same TP_NO then it just doesn't return a result insted of finding the next earliest PSAT.

    Hope that makes sense...
    Yep makes sense... lemme try something...

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    Try:

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Re: Query finding earlist date among common numbers

    Test Data sample.xlsx

    Ok, here's a quick & dirty on the test sample data table and based on what I'm looking for, the results I need.

  15. #15
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    xrajncajnx, did you try my last post... I think it might solve it.

    EDIT: only thing is... now we still get duplicates when the lowest TestDate is in more than one record... which result to return then? all? the only field that is not the same in those cases is TWR_No, don't know if you want them all, or just lowest or highest TWR?
    Last edited by Arkadi; 03-27-2015 at 03:09 PM.

  16. #16
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Re: Query finding earlist date among common numbers

    Quote Originally Posted by Arkadi View Post
    xrajncajnx, did you try my last post... I think it might solve it.
    Jackpot!!!


    Works like a charm.

  17. #17
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    You are OK with multiple results then for the same TP_No if the lowest date is in more than one record? Some results come up twice, with a different TWR_No.

  18. #18
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Re: Query finding earlist date among common numbers

    Quote Originally Posted by Arkadi View Post
    You are OK with multiple results then for the same TP_No if the lowest date is in more than one record? Some results come up twice, with a different TWR_No.
    Yes, multiple results are not an issue since the report I am dumping the data to has a vlookup fuction that is searching for that TP NO. As long as all the entries have the same date I don't have to worry with it just grabbing the first one it finds. If you can modify it where it just gives the first TWR number that would work too.

  19. #19
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Query finding earlist date among common numbers

    First? or Lowest?

    This gives the lowest TWR_No for the given criteria:

    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    02-14-2013
    Location
    Biloxi, Ms
    MS-Off Ver
    2013 or 2016
    Posts
    115

    Re: Query finding earlist date among common numbers

    Quote Originally Posted by Arkadi View Post
    First? or Lowest?

    This gives the lowest TWR_No for the given criteria:

    Please Login or Register  to view this content.
    That works as well. Again, thanks a ton.

+ 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. Finding common column values with duplicate numbers
    By ritavv in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 10-13-2010, 06:08 AM
  2. Finding Common Numbers
    By Dynamo418 in forum Excel General
    Replies: 2
    Last Post: 07-20-2010, 10:54 AM
  3. Return the Earlist Date
    By maddog9486 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-24-2008, 02:09 PM
  4. Finding the most common (and 2nd, 3rd most common) text
    By sprite_green in forum Excel General
    Replies: 2
    Last Post: 11-23-2006, 11:56 AM
  5. Finding most common occurence of values in cells containing letters and numbers
    By sparklyballs in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-18-2006, 07:20 AM

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