Depending on the grading scheme used in a course, the standard Moodle grade book options may not provide accurate grade representation. To customize how calculations are performed, Moodle supports the use of several common mathematical and statistical functions.
To build a custom formula, a proper syntax must be followed. Each formula begins with an “=” sign, followed by the function name then the values (arguments) to be calculated. Values must be enclosed in parenthesis (…). Standard arithmetic operators are supported in calculations.
Here are a few examples:
To include graded items such as assignments, quizzes, forums and so on in the calculation, each item must be represented by a unique ID name. The ID can be set when you initially create an activity or later by editing it. The ID you choose should be representative of the activity. For example, using the ID name “assignment” although an acceptable name would work if the course contained only one assignment. If more than one assignment is used, then coding the name in some unique way would be necessary to distinguish each. Here are some examples of ID names (assignment1, assignment2, Topic1Assignment, MidTermAssignment).
Notice that in this example of a custom formula, each ID name (assignment1,2,3,4) is enclosed within double square brackets [[….]]. These are required as part of the formula syntax, however, they should not be added to the item ID name when creating it. They are only used when adding ID names to a formula and tell Moodle that the names represent gradable activities.
This formula will total the individual assignment grades. The comma “,” acts like a “+” sign:
=sum([[assignment1]],[[assignment2]],[[assignment3]],[[assignment4]])
This formula will choose the largest or maximum value from all four assignments:
=max([[assignment1]],[[assignment2]],[[assignment3]],[[assignment4]])
This formula will calculate the average from the total individual assignment grades:
=average([[assignment1]],[[assignment2]],[[assignment3]],[[assignment4]])
In these examples, if the 4 assignments were grouped into a category, the result of any of the above functions would be recorded as the Total Category grade.
Here are a few basic guidelines when choosing grade item ID names:
This illustration shows the screen used to build a custom formula. The formula in this example is used to calculate weight factors of 4 different course assignments in "Fall essays" grade category.
Notice the combination of IDs, values and arithmetic operators in the formula.
Clicking the Add ID numbers without providing ID names, results in Moodle assigning unique arbitrary ID values to all items that do not already have an ID name
Also, note the ID numbers assigned to the 4 assignments. Other course grade items are listed (Ars Bene Vivendi Presentation and Latin Proverbs Quiz) but do not contain ID numbers. To add ID numbers to these grade items, you would enter the name you want to use (without the square brackets) in the text box beside each then click the Add ID numbers button.
Follow these steps to enter a custom formula: