Results 1 to 14 of 14
  1. #1
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108

    Calculating Average Weight - Broken SUM

    I have a database that creates a Total Loss Percent (columnT) on counts for adjusting that needs to be a weighted average based on these rules:



    if columnT is <5 then = 0%
    if columnT is >=90 then = 100%

    If either of those scenarios is true then they should not be part of the Weighted Average as well.

    Right now I have 3 created fields in the query:

    Weight: ([acresCounted]/[Forms]![frmCanolaCounts]![ActualAcres])
    SW: (IIf([columnT]<5 Or [columnt]>=90,0,[columnt])*[Weight])

    POLAcres: (IIf([columnT]<5 Or [columnt]>=90,0,[acresCounted])) - This is used to determine the number of acres to use to create the Weight where any count that has a Toal loss as per the rules is NOT included.

    On the form, in the detail, I have 2 created fields that are CRUCIAL to the formula to work. Everything works great but its just the last problem I can't figure out:

    Weight2 - Control Source: =([acresCounted]/(Sum([POLAcres]))) - Used to create the proper weight based on the rules
    SW1 - Control Source: =(IIf([columnT]<5 Or [columnt]>=90,0,[columnt])*[Weight2]) - used to create the proper Score x Weight value.

    Then in the form header, i have the Weighted Average field to determine the overall weight.

    AvgWeight - Control Source: =Sum([SW1])

    All in all the key to it working is being able to Sum([SW1]) But it breaks everything when trying to do that. Anyone have any ideas how I can sum ([SW1])???

    Thanks for the help, sorry if it comes off a bit confusing.

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    You say it breaks everything when trying to Sum([SW1]). How so is it breaking? Error codes? #Error? What?

  3. #3
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    yeah, between sw1, weight2, and avgweight all get #Error etc.

  4. #4
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    I think we would need a demo of your database where we can replicate the issue and walk the code with sample data.

  5. #5
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Quote Originally Posted by jwhite View Post
    I think we would need a demo of your database where we can replicate the issue and walk the code with sample data.
    Click image for larger version. 

Name:	cac.JPG 
Views:	11 
Size:	74.3 KB 
ID:	28229

    Thats what happens when i sum SW1
    When i sum SW there is no issues, my guess is because SW is created in the query, and SW1 is just a field on the detail.

  6. #6
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Could it be that....


    You can only use sum([sw1]) if sw1 is a field.

    From your description it is unclear whether sw is a field in your query and whether sw1 is a calculated text box.


    Sent from my iPad using Tapatalk

  7. #7
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    sw1 is just a text box with a control source that is: =(IIf([columnT]<5 Or [columnt]>=90,0,[columnt])*[Weight2])

    sw is a field i created in the query.

    I am feeling as though you just arent allowed to sum the text box if it isnt a field, any workaround?

  8. #8
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Could you use the query to create a field which has the values you need to add up?


    Sent from my iPad using Tapatalk

  9. #9
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Tried that, but apparently if you SUM in a query you also break everything, it appears it isnt allowed either. Hence why Weight2 had to be an unbound field as i couldn't SUM POL Acres in the query. This is turning into a seriously testing task.

  10. #10
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    How about still using the weight2: in a query but using Dsum function.

    Then you can use the sw1 in your query too. These can then be summed.


    Sent from my iPhone using Tapatalk

  11. #11
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Maybe I dont understand DSum, but POLAcres is being created in the query and a DSum is asking for a field in a table?

  12. #12
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    So long as the query has a name like qryname then

    you should be able to use
    Code:
    weight:([acresCounted]/(dsum("[POLAcres]","qryname"))
    in the query

  13. #13
    redekopp is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    I made the query qryAvgWeight, when I run the query it says it cannot find the name 'qryAvgWeight'

  14. #14
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Ok. [emoji848] do you have a version we can look at


    Sent from my iPhone using Tapatalk

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

Similar Threads

  1. Calculating an average from checkboxes?
    By Twitchie in forum Reports
    Replies: 2
    Last Post: 03-06-2014, 01:02 PM
  2. Replies: 9
    Last Post: 11-26-2013, 12:02 PM
  3. Calculating a weighted average
    By lugnutmonkey in forum Queries
    Replies: 2
    Last Post: 01-29-2013, 04:49 PM
  4. any idea on calculating average?
    By sk88 in forum Access
    Replies: 3
    Last Post: 08-30-2011, 11:32 PM
  5. Calculating average in table
    By prv in forum Database Design
    Replies: 1
    Last Post: 12-14-2010, 01:35 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