Results 1 to 3 of 3
  1. #1
    salisbut is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    52

    Can you do a custom calculation on a record in a query?


    In the database attached, I have a table called NET Position which adds the Market Sales and Market Purchases together. The problem is that for one of the entries, "EWEB", it is not a direct calculation. The SQL I came up with is below, but I can't seem to get it to work. Access says, "You tried to execute a query that does not include the specified expression as part of an aggregate function" I'm wondering if it is even possible to do a custom calculation on a query.
    NET Position: IIf([CompanyName]="EWEB",IIf(IsNull([qryMarketSales]![Revenue]),0,[qryMarketSales]![Revenue])+IIf(IsNull([qryMarketPurchases]![Cost]),0,[qryMarketPurchases]![Cost])-18500-(Sum([qryMarketSales]![Revenue])*0.01),IIf(IsNull([qryMarketSales]![Revenue]),0,[qryMarketSales]![Revenue])+IIf(IsNull([qryMarketPurchases]![Cost]),0,[qryMarketPurchases]![Cost]))
    If this isn't possible, do you have any ideas how I could get the EWEB calculation to appear differently?

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    A nested IIF statement can be difficult to untangle. Split the statement into discrete tasks in separate columns. This allows you to set it up 1 step at a time and see the results of each step as you go.

  3. #3
    salisbut is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    52
    Thanks! I got it! Nothing intermediate queries can't fix.

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

Similar Threads

  1. IIF() in a query calculation
    By bbylls in forum Queries
    Replies: 4
    Last Post: 12-03-2009, 04:42 PM
  2. Query Calculation
    By kellyd in forum Queries
    Replies: 5
    Last Post: 08-31-2009, 11:14 AM
  3. duplicate record based on calculation
    By Coolpapabell in forum Queries
    Replies: 4
    Last Post: 08-06-2009, 07:53 AM
  4. Easy Custom Calculation?
    By rjk1080 in forum Queries
    Replies: 6
    Last Post: 07-12-2009, 11:42 AM
  5. Custom Query Parameter Prompts-- Problem
    By tylerthompson in forum Forms
    Replies: 11
    Last Post: 07-07-2009, 10:28 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