Results 1 to 6 of 6
  1. #1
    kagoodwin13 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    181

    Trying to make summary figures for report, not working

    I am trying to include computed averages in the header of a report for a quick summary view. This average needs to ignore zero values so that they do not weigh down the average incorrectly. I have done this before in my database, but now that I am trying to generate another report with different data, the formula I used previously is not working.

    Previously, I had this code to calculate the average Cost Per Unit (CPU) given CPU and its annual volume, ignoring CPU values in records that have zero volume:


    Code:
    =Sum(IIf([A_CPU]=0,Null,([A_CPU]*[A Volume])))/Sum(IIf([A_CPU]=0,Null,[A Volume]))
    This code works. The report runs, and generates an average figure.

    Now, I am trying to use the same formula to calculate average cost per kilometer (for trucking) when given a rate and distance, ignoring rates in records with zero kilometers:
    Code:
    =Sum(IIf([KM]=0,Null,([Rate])))/Sum(IIf([KM]=0,Null,([KM])))
    When I run this formula though, I get an error message: "The expression is typed incorrectly, or it is too complex to be evaluated. For example, a numerical expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables."

    I'm not sure why the second formula, which is essentially the same as the first one, is too complex. Is there something I've missed?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is there some reason you enclosed the last [KM] in parens? "([KM])" I know it should not make any difference, just curious.

  3. #3
    kagoodwin13 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    181
    I just did a replacement of field names. I tried without parentheses, but I still get the same error.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Sometimes Access can get persistant errors. Try deleting the control, Compact and Repair, then open and add a new control with the same ControlSource.

  5. #5
    kagoodwin13 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Feb 2012
    Posts
    181
    Found the problem: the data type of [KM] was text, not number. D'oh!

    Thanks for your help.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Outstanding. Thanks for posting back with your success.

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

Similar Threads

  1. Tenure Summary Report Question
    By srmezick in forum Reports
    Replies: 3
    Last Post: 10-31-2011, 01:40 PM
  2. Creating Summary Page in Access Report
    By jakeman in forum Reports
    Replies: 5
    Last Post: 10-11-2011, 06:25 PM
  3. Order Summary Report
    By ryonker in forum Reports
    Replies: 1
    Last Post: 01-10-2011, 09:15 PM
  4. Replies: 2
    Last Post: 08-25-2010, 01:42 PM
  5. Summary Report Help Please?
    By solitaire in forum Reports
    Replies: 3
    Last Post: 03-03-2006, 08:10 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