Reference field before it is created

I want to change the value of a field based on a field after it. I have two fields, one called name and one called gender. I want that if gender is “Female” then the name should start with “Female”, and the same with “Male”. However, this doesn’t work if the gender field is after the name field. It works fine if gender is before. Is there a way to make it work with the gender field coming after?