Results 1 to 8 of 8
  1. #1
    kitoned is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    11

    How do I sum up values resulting from calculated fields in a query?

    I am trying to make an end of term report for a school. Briefly this is where the problem is:



    Exams query: e.g [ENG],[MATH],[SCIE] [Aggregate],[Total Aggregate],[Division]

    Aggregate is derived from the range of marks got e.g 75-100= Aggregate 1
    70-74 = Aggregate 2
    65-69 = Aggregate 3
    Asumming MK ENG=95,MK MATH=72, MK SCIE=65

    Aggregate ENG: IIf([MK ENG] Between 0 And 39,"9",IIf([MK ENG] Between 40 And 44,"8",IIf([MK ENG] Between 45 And 49,"7",IIf([MK ENG] Between 50 And 54,"6",IIf([MK ENG] Between 55 And 59,"5",IIf([MK ENG] Between 60 And 64,"4",IIf([MK ENG] Between 65 And 69,"3",IIf([MK ENG] Between 70 And 74,"2",IIf([MK ENG] Between 75 And 100,"1","Missed Exam")))))))))

    Ihave tested the above and it works great!.MK ENG=95 give Aggregate1,MK MATH=72 give Aggregate2 and MK SCIE=65 gives Agregate3

    The problem:

    May some one help me with the formula for determining the [total aggregates] from the above results so that I can latter on determine the division. Below is how I tried it:
    Total Aggregates:[Aggregate ENG]+[Aggregate MATH]+[Aggregate SCIE]. The result is 123 instead of "6"
    OR
    Is there any one with a better way of doing the above.
    Thaks in advance.

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    All you need to do is to convert your text result to a number like

    Total Aggregates: CInt([Aggregate ENG])+CInt([Aggregate MATH])+CInt([Aggregate SCIE])

  3. #3
    kitoned is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    11

    Thank you

    Quote Originally Posted by lfpm062010 View Post
    All you need to do is to convert your text result to a number like

    Total Aggregates: CInt([Aggregate ENG])+CInt([Aggregate MATH])+CInt([Aggregate SCIE])


    Thanks my dear. This really worked. I wish to be as good as you are in Access. Do you have a community? If so I should Join the same.

    kitoned

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Don't enclose the aggregate values within quote marks to begin with and CInt should not be necessary. CInt should error if value has alpha characters, like "Missed Exam".

    Switch() function is an option for nested IIf.

    Aggregate ENG: Switch([MK ENG]<40,9, [MK ENG]<45,8, [MK ENG]<50,7, [MK ENG]<55,6, [MK ENG]<60,5, [MK ENG]<65,4, [MK ENG]<70,3, [MK ENG]<75,2, [MK ENG]<=100,1)

    Arithmetic with Null returns Null. If any of the values are Null there will not be a sum. Handle Null.

    Total Aggregates: Nz([Aggregate ENG],0)+Nz([Aggregate MATH],0)+Nz([Aggregate SCIE],0)
    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.

  5. #5
    kitoned is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    11

    Thank you

    Quote Originally Posted by June7 View Post
    Don't enclose the aggregate values within quote marks to begin with and CInt should not be necessary. CInt should error if value has alpha characters, like "Missed Exam".

    Switch() function is an option for nested IIf.

    Aggregate ENG: Switch([MK ENG]<40,9, [MK ENG]<45,8, [MK ENG]<50,7, [MK ENG]<55,6, [MK ENG]<60,5, [MK ENG]<65,4, [MK ENG]<70,3, [MK ENG]<75,2, [MK ENG]<=100,1)

    Arithmetic with Null returns Null. If any of the values are Null there will not be a sum. Handle Null.

    Total Aggregates: Nz([Aggregate ENG],0)+Nz([Aggregate MATH],0)+Nz([Aggregate SCIE],0)

    This is actually better than the method before and I have tested it. It works without any error.
    But please I am still having a problem with the positions. This should be based on the total marks obtained from all subjects. See below:
    [Total marks] after "Sort Descending" in my query:
    Edward=590
    John=460
    Peter=400

    Please help me to assign positions 1st , 2nd and 3rd in the same query.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    So you calculate each student score and want them to sort by the total score?

    Did you apply sort order criteria to the calculated field?

    Post the sql statement of the query.
    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.

  7. #7
    kitoned is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    11
    Quote Originally Posted by June7 View Post
    So you calculate each student score and want them to sort by the total score?

    Did you apply sort order criteria to the calculated field?

    Post the sql statement of the query.
    This here on is my SQL:

    SELECT [StudentExamsQ].[Student Name], [StudentExamsQ].[Total Score],[StudentExamsQ].[Position in class] FROM StudentExamsQ ORDER BY [Total Score] DESC , [Position in class];

    As you can see from aboveTotal score is sorted Descending and I have no problem with that.
    Total Score: NZ([MK ENG],0)+NZ([MK MTC],0)+NZ([MK SCIE],0)+NZ([MK SST],0)+NZ([MK RE],0)+NZ([MK LUG],0)+NZ([MK LIT1],0+NZ([MK LIT2],0))

    The position in class is sorted Ascending (no need to add ASC). My problem is : How do I asign the positions to my Total scores before sorting.

    Here is part of the table I have :
    Student Name / Total score / Position in class / Expected Position in class
    Edward / 590 / ? / 1
    John / 460 / ? / 2
    Peter/ 400 / ? / 3

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Ranking in query is complex. Review http://allenbrowne.com/ranking.html
    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.

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

Similar Threads

  1. Query Resulting In Duplicate Entries
    By kestefon in forum Access
    Replies: 5
    Last Post: 12-04-2013, 03:28 PM
  2. Replies: 12
    Last Post: 10-01-2013, 12:59 PM
  3. Replies: 2
    Last Post: 06-10-2012, 01:10 PM
  4. Replies: 1
    Last Post: 03-27-2012, 05:25 PM
  5. Replies: 4
    Last Post: 01-04-2012, 02: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