Trying to update a formula field of table row when a reference field is updated

i have one more query, When I update the reference field, then the other field which i want to update(i.e. Available quantity), it updates only when its a field from same reference field, If i access the field from some other reference field, it doesn’t update available quantity after save. DO i need to change code snippet.