Results 1 to 3 of 3
  1. #1
    AshK is offline Novice
    Windows 11 Office 365
    Join Date
    Oct 2023
    Posts
    2

    Calculated Field in a Query

    I have a query with two tables (1 to M) I need to sum a value from the many side with totals turned on. Summing works fine [SumofAmount]. Then I am creating a profit field where a field from the parent table [Sold Price] subtracts the [SumofAmount]. But I am stuck here as I get error "enter Parameter". SQL is as under:

    Will appreciate some help.

    SELECT Vehicles.[VIN Number], Vehicles.Make, Vehicles.Model, Vehicles.Year, Vehicles.[Price (JYP)], Vehicles.[Price (AUD)], Vehicles.[Sold Price], Sum(tblExpenses.Amount) AS SumOfAmount, [Sold Price]-[SumofAmount] AS Expr1
    FROM Vehicles INNER JOIN tblExpenses ON Vehicles.VehicleID = tblExpenses.VehicleID
    WHERE (((Vehicles.SStatus) Like "*Sold*" And (Vehicles.SStatus)<>"Added to Fleet"))
    GROUP BY Vehicles.[VIN Number], Vehicles.Make, Vehicles.Model, Vehicles.Year, Vehicles.[Price (JYP)], Vehicles.[Price (AUD)], Vehicles.[Sold Price], [Sold Price]-[SumofAmount];

  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,929
    Can't have alias name of aggregate calculation in GROUP BY. Remove [Sold Price]-[SumOfAmount] from the GROUP BY clause.

    The Sum(Amount) must be repeated in the Profit calc. Make sure the query shows "Expression" under the Profit calculated field.

    The second filter criteria doesn't appear necessary.

    SELECT Vehicles.VehicleID, Vehicles.[VIN Number], Vehicles.Make, Vehicles.Model, Vehicles.Year, Vehicles.[Price (JYP)], Vehicles.[Price (AUD)], Vehicles.[Sold Price], Sum(tblExpenses.Amount) AS SumOfAmount, [Sold Price]-Sum([Amount]) AS Profit
    FROM Vehicles INNER JOIN tblExpenses ON Vehicles.VehicleID = tblExpenses.VehicleID
    WHERE SStatus LIKE "*SOLD*"
    GROUP BY Vehicles.VehicleID, Vehicles.[VIN Number], Vehicles.Make, Vehicles.Model, Vehicles.Year, Vehicles.[Price (JYP)], Vehicles.[Price (AUD)], Vehicles.[Sold Price];
    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
    AshK is offline Novice
    Windows 11 Office 365
    Join Date
    Oct 2023
    Posts
    2
    Very grateful for your help. Did not receive the notification else could thank you earlier.

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

Similar Threads

  1. Replies: 1
    Last Post: 02-03-2016, 06:54 PM
  2. Replies: 2
    Last Post: 12-30-2014, 01:32 PM
  3. Replies: 1
    Last Post: 08-25-2014, 01:23 PM
  4. Replies: 4
    Last Post: 03-20-2014, 03:52 PM
  5. Replies: 3
    Last Post: 02-13-2013, 10:15 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