# Formula

The Formula field type allows you to operate on the values of the other fields in your table. The formula field enables you to perform calculations such as addition, subtraction, multiplication, division, and more.

In the column config, users can write a function script which includes any mathematical functions, and returns a value.

The Formula field has access to the the `row` parameter, which contains the values of the other fields in the row. ## Example code snippets​

Dataset: Table contains list of students and their scores in different subjects. Let's see how we can create simple formulas for calculating their average, grade etc.

### Add numbers and find average​

This field will calculate and store the aggregate score of the student.

• Field Type: Formula
• Listener Fields: The three score fields.
• Output Field Type: Number
• Formula:
``const formula:Formula = async ({ row })=> {    const sum = row.subject1 + row.subject2 + row.subject3    const avg = sum/3    return avg;}``

### Percentage​

This field will calculate and store the percentage of the student.

• Field Type: Formula
• Listener Fields: The three score fields.
• Output Field Type: Percentage
• Formula:
``const formula:Formula = async ({ row })=> {    const sum = row.subject1 + row.subject2 + row.subject3    const avg = sum/3;    const percentage = avg/100;    return percentage}``

### If-Then-Else​

This field will calculate and store the grade of the student.

• Field Type: Formula
• Listener Fields: The three score fields.
• Output Field Type: Short Text
• Formula:
``const formula:Formula = async ({ row })=> {    const sum = row.subject1 + row.subject2 + row.subject3    const avg = sum/3;    if(avg>=90){        return "O"    }    else if(avg>=80 && avg<90){        return "A"    }    else if(avg>=70 && avg<80){        return "B"    }    else if(avg>=60 && avg<70){        return "C"    }    else if(avg>=50 && avg<60){        return "D"    }    else if(avg>=40 && avg<50){        return "E"    }    else{        return "F"    }}``

### Check fo greater than, less than or equal to​

This is a formula field which will calculate and store the result of the student, whether he passed or failed.

• Field Type: Formula
• Listener Fields: The three score fields.
• Output Field Type: Short Text
• Formula:
``    const formula:Formula = async ({ row })=> {        const avg = (row.subject1 + row.subject2 + row.subject3)/3        return avg >= 40 ? "Pass" : "Fail"    }``