Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    bill1234 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    7

    Combining Records with Sum

    Hi,
    I have a list of vendor records that I'm interested in combining (With the amount field summing). I am almost able to get what I want using the query wizard. The issue I'm having is that it appears that I am only getting records combined when the data in every field (other than the amount field, since that is being summed) is identical. There is a particular field (See very basic example attached) where I just want what ever data is in the first record on the combined query record. Is there any way to handle this?

    Attached Thumbnails Attached Thumbnails How I want my query to look.png   Original table data.png  

  2. #2
    bill1234 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    7
    The image on the left is my desired result, the image on the right is the original table.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Do you have an autonumber on that table?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Your totals query needs to remove the Sales region from its process.
    It makes no sense to have it the output as it's meaningless in respect of the total anyway.

    If you really have to have the Sales Region listed, you could use a DMax() or DMin() to get the first or last region, but it will slow down the query if there are lots of records.
    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 ↓↓

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Bill just curious why would you only want it to show the first Sales region but you are summing all the sales regions?

  6. #6
    bill1234 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    7
    Quote Originally Posted by Welshgasman View Post
    Do you have an autonumber on that table?
    Apologies, I do not know what you mean. I'm kind of an Access beginner.

  7. #7
    bill1234 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    7
    Hi, I know that data in the example doesn't make sense. For the data I would actually be using, it would make sense.

  8. #8
    bill1234 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    7
    Quote Originally Posted by Minty View Post
    Your totals query needs to remove the Sales region from its process.
    It makes no sense to have it the output as it's meaningless in respect of the total anyway.

    If you really have to have the Sales Region listed, you could use a DMax() or DMin() to get the first or last region, but it will slow down the query if there are lots of records.
    How do I use DMax or Dmin? I'm kind of a beginner.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Try googling for each and pick the microsoft link.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    If you open your present query and click on SQL View it will give you the SQL Query text of your current query.
    Copy and paste that here and we can probably assist.
    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 ↓↓

  11. #11
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,822
    Hi Bill
    Can you upload a copy of the database with no confidential data?

  12. #12
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    Here's one way... I did it with two queries. This one gets the first record for each vendor:
    Code:
    SELECT SalesInfo.Vendor, SalesInfo.[Address ], First(SalesInfo.[Sales Region]) AS [FirstOfSales Region]
    FROM SalesInfo
    GROUP BY SalesInfo.Vendor, SalesInfo.[Address ];
    (Beware the blank spaces... I attached to an Excel file)

    and the second:

    Code:
    SELECT FirstVendorAddress.Vendor, FirstVendorAddress.[Address ], FirstVendorAddress.[FirstOfSales Region], Sum(SalesInfo.[Amount Paid]) AS [SumOfAmount Paid]
    FROM FirstVendorAddress INNER JOIN SalesInfo ON FirstVendorAddress.Vendor = SalesInfo.Vendor
    GROUP BY FirstVendorAddress.Vendor, FirstVendorAddress.[Address ], FirstVendorAddress.[FirstOfSales Region];
    The second query uses the groupings from Query1 and joins back to the SalesInfo (original) table.

    (The more I read your question, the question seems to be a moving target.)
    Attached Files Attached Files
    Last edited by madpiet; 08-15-2024 at 03:41 PM. Reason: added files (example)

  13. #13
    bill1234 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    7
    Quote Originally Posted by Minty View Post
    If you open your present query and click on SQL View it will give you the SQL Query text of your current query.
    Copy and paste that here and we can probably assist.
    Here is the SQL text. It's "PayType" field that I would like to do this to.

    Code:
    SELECT DISTINCTROW [combine sheet].Cat, [combine sheet].VendorID, [combine sheet].Address1, [combine sheet].Address2, [combine sheet].City, [combine sheet].ST, [combine sheet].Zip, [combine sheet].PayType, [combine sheet].IDName, Sum([combine sheet].Amount) AS [Sum Of Amount]
    FROM [combine sheet]
    GROUP BY [combine sheet].Cat, [combine sheet].VendorID, [combine sheet].Address1, [combine sheet].Address2, [combine sheet].City, [combine sheet].ST, [combine sheet].Zip, [combine sheet].PayType, [combine sheet].IDName;

  14. #14
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    Code:
    SELECT  s.[v] as v, sum(s.[p]) as p , first(s.[a]) as a,first( s.[s]) as sFROM s
    group by s.[v];
    this is the result u ask for but make no sense to me , i expect sales region is also part of sum , then group by s.[v],s.[s]
    Attached Thumbnails Attached Thumbnails Screenshot 2024-08-16 210312.png   Screenshot 2024-08-16 210335.png  

  15. #15
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    Quote Originally Posted by bill1234 View Post
    Here is the SQL text. It's "PayType" field that I would like to do this to.

    Code:
    SELECT DISTINCTROW [combine sheet].Cat, [combine sheet].VendorID, [combine sheet].Address1, [combine sheet].Address2, [combine sheet].City, [combine sheet].ST, [combine sheet].Zip, [combine sheet].PayType, [combine sheet].IDName, Sum([combine sheet].Amount) AS [Sum Of Amount]
    FROM [combine sheet]
    GROUP BY [combine sheet].Cat, [combine sheet].VendorID, [combine sheet].Address1, [combine sheet].Address2, [combine sheet].City, [combine sheet].ST, [combine sheet].Zip, [combine sheet].PayType, [combine sheet].IDName;
    Did the question change while I was away?

    I answered your original question. Maybe you need to explain it better with an example of what you're starting with and what your expected results are.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Combining duplicate records
    By Subs in forum Queries
    Replies: 4
    Last Post: 11-13-2013, 08:53 AM
  2. Combining Records
    By admessing in forum Queries
    Replies: 2
    Last Post: 12-15-2011, 05:41 PM
  3. Query for combining records
    By alpinegroove in forum Queries
    Replies: 6
    Last Post: 01-28-2011, 07:29 AM
  4. Combining / Merging Records
    By alpinegroove in forum Access
    Replies: 8
    Last Post: 01-27-2011, 09:43 AM
  5. combining field from two records into one
    By RedGoneWILD in forum Queries
    Replies: 8
    Last Post: 07-13-2010, 09:47 AM

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