This is a solution for the following scenario. I thought it worth sharing:
The teacher wants to replace the lowest exam score for a semester with the final exam score if the final exam is higher than the lowest exam score. The idea is that students who improve on the content in the final exam can recover some credit for an earlier exam by performing well on this final.
Here is how to accomplish this in Moodle 3.7:
Create the grade items, either as manual grade items, assignments, quizzes, or any other graded activity. We will call them Exam 1, Exam 2, Exam 3, and Final Exam.
Put exams 1, 2, and 3 in their own categories.
Edit the calculation for these three categories. Make sure you remember to put in the IDs for the grade items in this step. In the calculations below the IDs are EXAM1, EXAM2, EXAM3, and FINALEXAM.
For the Category containing Exam 1, put this in the grade calculation box:
For the Category containing Exam 2, put this in the grade calculation box:=if(AND(EXAM2<=min(EXAM1,EXAM2,EXAM3),EXAM2<EXAM1,FINALEXAM>EXAM2),FINALEXAM,EXAM2)
For the Category containing Exam 3, put this in the grade calculation box:
The gradebook setup page looks like this. Everything here is contained in a category called "Exam Tests":
Open the editing for the category calculations is here:
Input the custom calculations above in the box at the top. Don't forget to specify the Grade item IDS where the arrows are in the following image:
It's worked under every scenario I can think of. Let me know if you try it!