Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Averages by row 2

Status
Not open for further replies.

Boneve

Technical User
Aug 16, 2007
1
US
I'm working with a gradebook. I am trying to make a query with Averages by row. Here are the columns

Name Test Test Rem1 TestRem2 Test Ave


I need an average of the test

I tried this, which did not work.

Test Ave: IIf ([Test]>1,[Test])

OR IIf([Test Rem1]>1,[Test]+[Test Rem1] / 2)
IIf([Test Rem2]>1,[Test]+[Test Rem1]+[Test Rem2] /3)
Any help would be greatly appreciated

Thank you
Boneve
 
First - the IIF takes 3 arguments. Highlight IIF and hit F1 to see an example.
 
there are several routines posted in these fora which illustrate aggregate function techniques for rowset values. you should be able to find any / several of them using search / advanced search.

For the simple process of grade book average, the following should suffice, but please note that it has not been extensively tested

Code:
Public Function basAvg(ParamArray varMyVals()) As Variant


    'Michael Red 8/16/2007
    'To return the AVG of a series of values

    'Sample Usage:
    '? basAvg(1, 2, 3, 4, 5, ,6 -7)
    '2
    Dim Idx As Integer
    Dim Jdx As Integer
    Dim MySum As Variant

    For Idx = 0 To UBound(varMyVals())
        If (IsMissing(varMyVals(Idx))) Then
            GoTo NextVal
        End If
        If (IsNumeric(varMyVals(Idx))) Then
            MySum = MySum + varMyVals(Idx)
            Jdx = Jdx + 1
        End If
NextVal:
    Next Idx

    If (Jdx > 0) Then
        basAvg = MySum / Jdx
     Else
        basAvg = 0
    End If

End Function

MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top