Results 1 to 12 of 12
  1. #1
    Chatholo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    34

    Issue with "Group by" in a query

    Hi,



    I am trying to compare the data of two tables through a query, I thought that was easy but it looks like I am running into at least a couplea of issues.

    The first one is I want to compare based on the LHSID item but as you can see in my query datasheedt it doesn't fully group it - I have 3 lines. I am guessing it is due to the 1 to many relashionship but not to sure how to fix it.

    The second problem is that my last field is a calculated field to check the variance of the two other columns, i have tried to change the "Total" criteria but then it says it doesn't recognize it.....

    Any help is appreciated! The aim is really onlyu to compare these two tables based on the LHSID.
    Attached Thumbnails Attached Thumbnails Query.PNG   Qexpression.PNG   QVariance.PNG  

  2. #2
    stmoong is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Try the following.

    1) Remove the grouping.
    2) Remove the tblProgramBudget.LHSID field.
    3) Double click on the join (the line between the table).
    4) The "Join Properties" window will be displayed. Choose option 2, which is to include ALL records from 'tblProgramList' and only those records from 'tblProgramBudget' where the joined fields are equal.
    5) Click OK.

    The query should work now.

  3. #3
    Chatholo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    34
    Thanks Stan. I just tried it but it doesn't give me the expected result. My join is already on #2, hence the reason why (i think) i end up with a long list of item not grouped by LHSID. Also I need to keep the tblProgramBudget.LHSID field otherwise I won't know which items are in this table and not in the Program list one ...

    Basically I want to end up to something like that, grouped by LHSID:
    LHSID (Tblprogramlist) - LHSID (Tblbudget) - Heads (Tblprogramlist) - Heads (Tblbudget) - Check (calculated field)

    C.

  4. #4
    stmoong is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    By right, shouldn't all LHSID be in tblProgramList since that is the master table?

    If the are LHSID in tblProgramBudget but not found in tblProgramList, then you have missing master data.

    From the screenshot, it doesn't appear to be Left Join. The screenshot shows one where you will only get results for matching records.

    The grouping is normally not necessary, because tblProgramList will have unique LHSID. Unless you have many records in tblProgramBudget that have the same Salary Heads or have no values, then probably grouping would be useful.

  5. #5
    Chatholo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    34
    My tblProgramList is my source data, the other one is manipulated data, linked to a form and split by region, business etc... I am trying to create a query that will check that the new allocations still match the original numbers. That's why I have two tables with the same ID.

  6. #6
    stmoong is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Your tblProgramList and tblProgramBudget is a 1-to-many relationship. But your query join property does not appear to be set to Left Join.

    There is however a problem in the tblProgramBudget in that no primary key is specified to uniquely identify each record. You can use autonumber as the primary key. Using LHSID to update record in tblProgramBudget is dangerous, because you will update all the records with the same LHSID in tblProgramBudget.

  7. #7
    Chatholo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    34
    Click image for larger version. 

Name:	Join properties.PNG 
Views:	2 
Size:	14.3 KB 
ID:	13105
    Here is a screenshot of my join properties - I am confused, is this what you call "left join". I set it to what you mentionned in the first reply #2.

    In regards to the Key I guess i can add it to autonumber no issue with that.
    For the last one, even though I am using LHSID to update records I am not update in the same field, so i don't believe (but I am new in access) that it will be an issue. the initial one is called [average heads] and my new input [Heads]

  8. #8
    stmoong is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    Yes, the latest screenshot shows the left join for tblProgramList.

    With the autonumber ID field, you basically tell Access to update the record with the ID, which is unique. If you use the LHSID to update the tblProgramBudget, then you can end up with more than 1 records being updated.

    For example, you have 10 records in tblProgramBudget with the LHSID="0010". If you tell Access to update the salary for records with LHSID="0010", then, all 10 records will be updated.

  9. #9
    Chatholo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    34
    I appreciate your help, but I don't understand how that helps me with my initial question on how to perform a "variance" check between these two tables.

  10. #10
    stmoong is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    If the relationship of the data is correct, then the query is relatively easy.

    I created these sample tables and query to illustrate the concept.

    tblProgramList: Click image for larger version. 

Name:	01.png 
Views:	2 
Size:	4.0 KB 
ID:	13106

    tblProgramBudget: Click image for larger version. 

Name:	02.png 
Views:	6 
Size:	4.1 KB 
ID:	13111

    ProgramQuery: Click image for larger version. 

Name:	03.png 
Views:	2 
Size:	5.1 KB 
ID:	13108 Click image for larger version. 

Name:	04.png 
Views:	4 
Size:	4.4 KB 
ID:	13109

    Result: Click image for larger version. 

Name:	05.png 
Views:	3 
Size:	5.5 KB 
ID:	13110
    Last edited by stmoong; 07-17-2013 at 08:53 PM. Reason: Fix screenshots

  11. #11
    Chatholo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    34
    Thanks Stan. This is what I am after but on the result table how can I have only 1 line by LHSID type?

  12. #12
    stmoong is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    If your requirement is to get the average variance, then you need to modify the query to something like this.
    Click image for larger version. 

Name:	06.png 
Views:	4 
Size:	4.2 KB 
ID:	13112

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

Similar Threads

  1. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  2. Replies: 1
    Last Post: 08-23-2012, 08:32 AM
  3. Replies: 4
    Last Post: 04-07-2012, 02:33 PM
  4. Two Different "Group By"'s in the Same Query
    By Lady_Jane in forum Queries
    Replies: 3
    Last Post: 04-08-2011, 11:31 AM
  5. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM

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