Results 1 to 10 of 10
  1. #1
    marlic_gayo is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5

    Post Match same field in same column

    i have following data



    Company name Financial period description status
    ABC 2020 Project Handed over Closed
    XYZ 2021 Just started In-Process
    XYZ 2021 First obj done In-Process
    XYZ 2021 Project Handed over Closed
    ABC 2022 Just Started In-Process

    I have a master query(Main) which includes log entries of for each company, single company has multiple entries for example 1. when project started 2. step one 3 step two 4 completion.
    Each entry has a field(status) which can either be selected (In-process or closed). so intuitively after multiple log entries only the recent entry (project handed over) should show status=closed while all other interim entries show status= in process.
    So for any company which is not completed should not have any entry with status=closed. so basically i want to show the companies that are still in-process.

    I have been running the following sql query

    Code:
    SELECT [Master Query].[Action Date], *FROM [Master Query]
    WHERE ((([Master Query].Status)="In-Process") AND (([Master Query].[Company Name]) Not In (SELECT [Company Name] From [Master Query] where Status= "Closed")));
    Result required: Should show me ABC as "in Process"
    Results obtained: No company "in process"

    This query returns me only those entries that do not have a subsequent status=closed entry. the code was working just fine for the whole year. Now since we have moved into new financial year, the code cannot accurately give results, because there will be again multiple entries for that same company where status=in process but since they have previous status=closed entry, the above code skips those companies.

    I have another field [Master Query].[Financial Period] which can work as a differentiator, so i want to modify the above query so that it only matches status (In process or closed) of the same company and OF THE SAME YEAR.
    So what i actually want the code to is the following:
    Show me companies that have status=in process but if they have status=closed, do not show me those. do this for each financial periods do not run this over different financial periods

    i have tried my best to explain my case. Please help me with this.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    With the given sample, exactly what do you want for output? Only the second ABC record?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    marlic_gayo is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5
    Exactly yes, using the financial period as differentiator.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Consider:

    SELECT * FROM [TableName]
    WHERE Status="In-Process" AND [Company Name] Not In (SELECT [Company Name] From TableName AS T WHERE Status = "Closed" AND T.[Financial Period] = TableName.[Financial Period]);

    Strongly advise not to use spaces in naming convention.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Using the date as a grouping field, something like

    Code:
    SELECT [Company name],	Max([Financial period]), [description], [status] 
    FROM [Master Query]
    WHERE Status = "In-Process"
    Group by [Company name], [description], [status]
    This assumes [Financial Period] is a number not text.

    Spaces in fields names should be avoided as it means you have to enclose them in [ ] all the time.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    marlic_gayo is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5
    Hi noted for future.
    The query still returns the same results.

  7. #7
    marlic_gayo is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5
    Hi unfortunately its text field

  8. #8
    marlic_gayo is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5
    Quote Originally Posted by June7 View Post
    Consider:

    SELECT * FROM [TableName]
    WHERE Status="In-Process" AND [Company Name] Not In (SELECT [Company Name] From TableName AS T WHERE Status = "Closed" AND T.[Financial Period] = TableName.[Financial Period]);

    Strongly advise not to use spaces in naming convention.
    Thanks Works like charm

  9. #9
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    given your data example this query

    SELECT A.[Company name], A.[Financial period], Max(A.status) AS MaxOfstatus
    FROM Table1 AS A LEFT JOIN Table1 AS B ON (A.[Financial period] = B.[Financial period]) AND (A.[Company name] = B.[Company name])
    GROUP BY A.[Company name], A.[Financial period]
    HAVING (((Max(A.status))="in-process") AND ((Min(B.status))<>"closed"));

    returns
    Company name Financial period MaxOfstatus
    ABC 2022 In-Process

    substitute your query name for the table name


    However I suspect you are suffering from Excelitis, (using multiple steps when only one is required) query probably needs to be done as part of your original query or from it's data source. I note the example data does not include the field Action Date for example - if it did, you could simply look at the latest date per company or latest date per company and period

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You might also consider giving each Project a unique identifier.
    I agree with :
    ---NOT using a naming convention that allows embedded spaces in object names,
    ---date/timestamp on status/action date.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. If data does not match in Column 1 Use Column 2
    By P3ndrag0n in forum Queries
    Replies: 2
    Last Post: 02-11-2016, 11:32 AM
  2. Replies: 1
    Last Post: 06-12-2015, 02:21 PM
  3. Replies: 10
    Last Post: 04-22-2015, 01:33 AM
  4. Replies: 4
    Last Post: 02-06-2014, 03:35 PM
  5. Adding text to column if match
    By niihla10 in forum Access
    Replies: 0
    Last Post: 08-26-2009, 01:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums