A grade formula is a calculation used to determine grades that is generally based on a combination of 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. (Preset calculations include mean of grades, weighted mean of grades, simple weighted mean of grades, and sum of grades. For help using preset calculations, see Grade Calculation in Moodle.)
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 columns in your formula), then you can enter the text of the custom formula.
Open the Edit Calculation Page
To open the edit calculation page in Moodle:

Open the Gradebook and in the tabs at the top of the page, click Categories and items. The Categories and Items page will open.

Next to the column for which you would like to create a calculation, click the Edit Calculation icon ( ). The Edit calculation page will open.
Note: The Edit Calculation icon will only be available next to Category total columns, manually created columns, and the Course Total column.
Assign Column ID Numbers
To use existing grade items in a custom formula, you must first assign ID Numbers, which are used as variables in the text of the custom 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 your calculation.

On the Edit Calculation page, below the calculation field, is a list 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, then you can use this ID number in your formula.

After you have entered ID numbers, check them carefully; you will only have once 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 Calculation
Calculations for the Moodle gradebook follow the pattern of formulas/functions in popular spreadsheet programs. Formulas start with an equal (=) 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(number, 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 (*) gives the product of two items: [[item1]]*[[item2]]

a backslash (/) divides items: [[item1]]/[[item2]]
A full list of available functions can be found at: http://docs.moodle.org/20/en/grade/edit/tree/calculation.
Note: There are no logical conditional (IF, AND, OR) statements in the Calculator tool.

In the Calculation entry box, start by entering an equal sign (=)

Enter the calculation function you wish to use (see above).

Enter your ID numbers into the double square brackets, for example
=sum([[quiz]][[quiz2]][[quiz3]]).

Separate the bracketed ID numbers with a comma, for example
=sum([[quiz1]],[[quiz2]],[[quiz3]]).

Click Save Changes (below the calculation entry box).