Custom Grade Formulas in the Moodle Gradebook [1]
A grade formula is a calculation used to determine grades that is based on other grade items and numeric calculations. Instructors can use the Calculation tool in the Moodle Gradebook to create their own formulas as an alternative to Moodle's preset calculations.
Note: Preset calculations include Mean of Grades, Custom Weights, and Natural. For help using preset calculations, see Grade Calculation in Moodle [2].
This page describes the process of creating a custom grade formula. First you will assign ID values to columns in the gradebook (used to identify items in your formula), then you will input the custom formula.
Open the Edit Calculation Page
To open the edit calculation page in Moodle:
 In the Administration block, under Course Administration, click Gradebook setup. The gradebook will open to the Gradebook setup page.

Locate the item for which you would like to create a calculation, and under Actions (at far right), click Edit, and from the dropdown menu select Edit Calculation. The Edit calculation page will open.
Note: The Edit Calculation icon will only be available next to category totals, manually created grade items, and the Course total.
Assign Column ID Numbers
To use existing grade items in a custom formula, you must first assign ID Numbers (short text labels), which are used as variables in the text of the formula. Columns are referenced in a formula by placing double square brackets ( [[...]] ) around the ID Number. For example, if you have a grade item with the ID Number "Quiz3", you will refer to this item as "[[Quiz3]]" in the formula.

On the Edit Calculation page, below the Calculation field, is a list of all grade items. Enter an ID number value for each grade item you want to use in the formula. Values can include text, spaces, and numbers, however short names are strongly recommended (i.e., "Quiz3", "Exam 1", etc.).
Note: If a grade item already has an ID number (surrounded with double square brackets) instead of an input field, you can use this ID number in your formula.  After you have entered ID numbers, check them carefully; you will only have one chance to save them.
 To save your ID numbers, click Add ID numbers (at bottom). The page will refresh to show an updated list of grade items and corresponding ID numbers.
Create a Formula
Custom formulas for the Moodle gradebook follow the pattern of formulas/functions in popular spreadsheet programs. Formulas start with an equals (=) sign, and use common mathematical operators and functions to produce a single numerical output. This output is then used as the computed value for the grade item you are editing.
Common calculation functions and operations include the following:
 average([[item1]], [[item2]]...): Returns the average of a sample
 max([[item1]], [[item2]]...): Returns the maximum value in a list of arguments
 min([[item1]], [[item2]]...): Returns the minimum value in a list of arguments
 round([[item1]], count): Rounds a number to a predefined accuracy. For example, "round([[item1]], 2)" will round the value of "item1" to the second decimal place.
 sum([[item1]], [[item2]]...): Returns the sum of all arguments
 an asterisk (*) multiplies two items: [[item1]]*[[item2]]
 a forward slash (/) divides items: [[item1]]/[[item2]]
A full list of available functions can be found at: https://docs.moodle.org/30/en/Grade_calculations. [3]
Note: There are no logical conditional (IF, AND, OR) statements in the Calculator tool.

In the Calculation box, start by entering an equals sign (=).

Enter the calculation function you wish to use (see above).
Example: =sum 
Enter an open parenthesis.
Example: =sum( 
Enter your ID numbers being sure to include the double square brackets.
Example: =sum([[quiz1]] 
Separate additional ID numbers with a comma.
Example: =sum([[quiz1]],[[quiz2]],[[quiz3]] 
Enter a close parenthesis.
Example: =sum([[quiz1]],[[quiz2]],[[quiz3]])  Click Save Changes (below the Calculation box).