If you put it in the controller on the create action it won’t run if the user update, maybe these filed once inserted, update is not allowed
If you put in beforeSave it is always runned does not matter which controller run it, it is the best place if you need to run it in several part of the code:
For example you insert update data via:
create and update action
API interface
command
cronjob
import data from file procedure
A third option is to put the calculation in a input validation method. If both input pass the validation , store the formula result in the column.
In this way, using scenario, you can chose if you want to perform the validation and therefore the calculation.
@jacmoe even if your code is correct it does not do what Gustavo need.
Your code does the calculation only on insert.
Looking at the code Gustavo posted (even if it is wrong since on insert does the same calculation twice) it seem he need to do the calculation on both update and insert.